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);
 }
相关推荐
观无30 分钟前
VisionPro的二维码识别
c#
Fairy要carry1 小时前
面试:LLM-分词
开发语言·c#
kylezhao201911 小时前
C# 文件的输入与输出(I/O)详解
java·算法·c#
kylezhao201912 小时前
C# TreeView 控件详解与应用
c#
FL162386312914 小时前
C# winform部署yolo26-obb旋转框检测的onnx模型演示源码+模型+说明
开发语言·c#
hoiii18720 小时前
C# 俄罗斯方块游戏
开发语言·游戏·c#
chao18984421 小时前
C#实现OMRON FINS-TCP协议与PLC通信
网络·tcp/ip·c#
ytttr87321 小时前
基于C# WinForms实现多窗口通信
开发语言·microsoft·c#
fengfuyao9851 天前
基于C# WinForm实现的串口调试助手源码
开发语言·c#
上海物联网1 天前
Prism WPF中的自定义区域适配器解决了什么问题?在项目中怎么实现一个自定义适配器
wpf