WPF 绑定 DataGrid 里面 Button点击事件 TextBlock 双击事件

TextBlock双击事件

csharp 复制代码
<DataGridTemplateColumn Width="*" Header="内标">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Grid>
                <TextBlock
                    Background="Transparent"
                    Tag="{Binding InternalId}"
                    Text="{Binding InternalId}">
                    <TextBlock.InputBindings>
                        <MouseBinding
                            Command="{Binding DataContext.InternalClickCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"
                            CommandParameter="{Binding}"
                            MouseAction="LeftDoubleClick" />
                    </TextBlock.InputBindings>
                </TextBlock>
            </Grid>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Button点击事件

csharp 复制代码
<DataGridTemplateColumn Width="*" Header="内标">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Grid>
                <Button
    Background="Transparent"
    BorderBrush="Transparent"
    Command="{Binding Path=DataContext.InternalClickCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"
    Content="{Binding InternalId}"
    Tag="{Binding InternalId}" />
            </Grid>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
csharp 复制代码
 [RelayCommand]
 private void InternalClick(GuantifyCompound guantifyCompound)
 {
     MessageBox.Show("=InternalClick=" + guantifyCompound.LeftWidth);
 }
相关推荐
XiaoyuEr_668821 分钟前
C#中属性和字段的区别
开发语言·c#
火星papa23 分钟前
C# 利用log4net 工作台打印和保存到文件
c#
ghost14330 分钟前
C#学习第19天:多线程
开发语言·学习·c#
钢铁男儿33 分钟前
C# 类的基本概念(声明类)
c#
李宥小哥40 分钟前
Redis03-基础-C#客户端
开发语言·缓存·中间件·c#
姜行运3 小时前
数据结构【堆和链式结构】
数据结构·算法·c#
极小狐4 小时前
极狐GitLab 议题权重有什么作用?
开发语言·数据库·chrome·c#·gitlab
董先生_ad986ad7 小时前
C# 中的 `lock` 关键字本质
开发语言·c#
爱编程的鱼11 小时前
C# 枚举(Enum)声明与使用详解
java·windows·c#
冰茶_13 小时前
C#中常见的设计模式
java·开发语言·microsoft·设计模式·微软·c#·命令模式