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);
 }
相关推荐
时光追逐者16 小时前
【拾遗补漏】.NET 常见术语集
微软·c#·.net
秋雨雁南飞17 小时前
c# 使用Memory实现Redis入队出队功能
redis·c#
2501_9307077818 小时前
使用C#代码添加或删除PPT页面
开发语言·c#·powerpoint
小码编匠21 小时前
WPF 绘制图表合集-LiveCharts
后端·c#·.net
C# 学习者1 天前
C# 为异步函数实现WaitAsync方法
java·前端·c#
唐青枫1 天前
C#.NET MemoryCache 深入解析:本地缓存机制与最佳实践
c#·.net
拾荒的小海螺1 天前
C#:OpenCvSharp 实现图像处理的技术指南
开发语言·图像处理·c#
张人玉1 天前
C#WPF UI路由事件:事件冒泡与隧道机制
ui·c#·wpf
雪域迷影1 天前
C#中通过get请求获取api.open-meteo.com网站的天气数据
开发语言·http·c#·get
yue0081 天前
C#类继承
java·开发语言·c#