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);
 }
相关推荐
yngsqq1 小时前
二维异形排版、二维装箱(NPF碰撞检测)——CAD c#二次开发
开发语言·javascript·c#
切糕师学AI1 小时前
.NET 如何引用两个不同版本的dll?
c#·.net
烛阴4 小时前
不只是Public与Private:C#访问修饰符全方位解读
前端·c#
wuty0074 小时前
WPF 调用 Win32的SetWindowDisplayAffinity 函数 实现捕获屏幕时,过滤指定的窗口
wpf·setwindowdisplayaffinity·过滤窗口·wgc·截屏过滤窗口
秋雨雁南飞4 小时前
c# 多项目编译发布
c#
张人玉5 小时前
C#Https协议相关知识点
开发语言·https·c#
Byron Loong5 小时前
【C#】VS调试——带参调试
开发语言·c#
TracyCoder1235 小时前
RocketMQ技术原理简单解析:从架构到核心流程
架构·wpf·rocketmq
故事不长丨5 小时前
解锁C#编程秘籍:封装、继承、多态深度剖析
开发语言·数据库·c#
努力小周6 小时前
基于STM32物联网智能老年人防摔系统
stm32·单片机·嵌入式硬件·物联网·c#·课程设计