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);
 }
相关推荐
我是苏苏4 小时前
C#基础:Winform桌面开发中窗体之间的数据传递
开发语言·c#
水果里面有苹果10 小时前
20-C#构造函数--虚方法
java·前端·c#
[纳川]14 小时前
把word中表格转成excle文件
开发语言·c#·word
lph197215 小时前
快速分页wpf
c#
试行16 小时前
C#System.Runtime.InteropServices.ExternalException (0x80004005): GDI+ 中发生一般性错误。
c#
❀always❀17 小时前
深入浅出分布式限流(更新中)
分布式·wpf
每日出拳老爷子19 小时前
[C#] 使用TextBox换行失败的原因与解决方案:换用RichTextBox的实战经验
开发语言·c#
程序猿多布1 天前
C# 值拷贝、引用拷贝、浅拷贝、深拷贝
c#
阿蒙Amon1 天前
C#随机数生成全面详解:从基础到高级应用
服务器·网络·c#