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);
 }
相关推荐
TA远方2 小时前
【WPF】桌面程序开发之窗口的用户控件详解
c#·wpf·usercontrol·用户控件·控件属性
BeanGo3 小时前
WPF文本框无法输入小数点
wpf
.net开发3 小时前
WPF项目中使用Caliburn.Micro框架实现日志和主题切换
c#·.net·wpf
一丝晨光7 小时前
标准输入输出
java·c++·python·c#·go·c·io
月落.8 小时前
C#中的报文(Message)
开发语言·c#
湛江小浪石(峰)9 小时前
今天推荐一个文档管理系统 Dorisoy.Pan
c#
红黑色的圣西罗9 小时前
C# CS1612 尝试修改集合中值类型的情况
c#
初级代码游戏10 小时前
C# winforms DataGridView 隐藏行 解决“与货币管理器的位置关联的行不能设置为不可见”
开发语言·c#·datagridview·隐藏行
湖南罗泽南11 小时前
C# 事件和委托的详细介绍
服务器·数据库·c#