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);
 }
相关推荐
bugcome_com7 小时前
零基础入门C#:一篇搞懂核心知识点
c#
程序员敲代码吗10 小时前
如何通过命令行启动COMSOL的参数化、批处理和集群扫描
java·c#·bash
缺点内向12 小时前
C#: 告别繁琐!轻松移除Word文档中的文本与图片水印
c#·自动化·word·.net
喵叔哟13 小时前
06-ASPNETCore-WebAPI开发
服务器·后端·c#
2501_9307077813 小时前
使用 C# .NET 从 PowerPoint 演示文稿中提取背景图片
c#·powerpoint·.net
初级代码游戏14 小时前
套路化编程 C# winform 自适应缩放布局
开发语言·c#·winform·自动布局·自动缩放
大空大地202615 小时前
流程控制语句--switch多分支语句使用、while循环语句的使用、do...while语句、for循环
c#
kylezhao201917 小时前
C#序列化与反序列化详细讲解与应用
c#
JQLvopkk17 小时前
C# 实践AI :Visual Studio + VSCode 组合方案
人工智能·c#·visual studio
故事不长丨17 小时前
C#线程同步:lock、Monitor、Mutex原理+用法+实战全解析
开发语言·算法·c#