首页 > 其他分享 >wpf datagrid绑定行选中状态

wpf datagrid绑定行选中状态

时间:2024-06-06 15:23:05浏览次数:19  
标签:DataContext para -- 绑定 datagrid wpf config row

样式如下

      <DataGrid Margin="0,6,0,0" HeadersVisibility="All" RowHeaderWidth="60" HorizontalScrollBarVisibility="Visible" AutoGenerateColumns="False"  
                  ItemsSource="{Binding DisplayConfigList}" hc:DataGridAttach.ShowRowNumber="False" hc:DataGridAttach.ShowSelectAllButton="True" 
                  >
            <DataGrid.RowHeaderTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding IsSelected,RelativeSource={RelativeSource AncestorType=DataGridRow}}" Name="dataGridRowCheckBox">
                            <hc:Interaction.Triggers>
                                <hc:EventTrigger EventName="Checked">
                                    <!--<hc:EventToCommand Command="{Binding  CheckCommand}" PassEventArgsToCommand="True" />-->
                                    <hc:EventToCommand Command="{Binding DataContext.CheckCommand,RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding .,RelativeSource={RelativeSource AncestorType=DataGridRow}}" />
                                </hc:EventTrigger>
                                <hc:EventTrigger EventName="Unchecked">
                                    <!--<hc:EventToCommand Command="{Binding  CheckCommand}" PassEventArgsToCommand="True" />-->
                                    <hc:EventToCommand Command="{Binding DataContext.CheckCommand,RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding .,RelativeSource={RelativeSource AncestorType=DataGridRow}}" />
                                </hc:EventTrigger>
                            </hc:Interaction.Triggers>
                        </CheckBox>
                    </StackPanel>
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>
            <DataGrid.Columns>
                <!--<DataGridCheckBoxColumn  Width="auto"  Binding="{Binding ISSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Header="任务状态"/>-->
                <DataGridTemplateColumn Header="操作">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                <TextBlock Text="{Binding ISSelected}"/>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

command内容如下

  CheckCommand = new BaseCommand((para) =>
  {
      if(para is DataGridRow row)
      {
          if(row.DataContext!=null && row.DataContext is VMIndexRunningConfig config)
          {
              config.ISSelected = row.IsSelected;
          }
      }
  });

标签:DataContext,para,--,绑定,datagrid,wpf,config,row
From: https://www.cnblogs.com/ives/p/18235203

相关文章

  • tapPromise 函数 (绑定hooks方法)tapable 库,创建自定义插件的库
    tapPromise函数(绑定hooks方法)tapable库,创建自定义插件的库刚看到了一个插件的use函数//引入组件use(plugin:IPluginClass,options?:IPluginOption){if(this._checkPlugin(plugin)&&this.canvas){this._saveCustomAttr(plugin);constpluginRu......
  • 界面控件Telerik UI for WPF中文教程 - 用RadSvgImage升级应用程序UI
    TelerikUIforWPF拥有超过100个控件来创建美观、高性能的桌面应用程序,同时还能快速构建企业级办公WPF应用程序。UIforWPF支持MVVM、触摸等,创建的应用程序可靠且结构良好,非常容易维护,其直观的API将无缝地集成VisualStudio工具箱中。TelerikUIforWPF中的RadSvgImage组件使......
  • linux 遇到硬盘设备名称会改变时,可以使用udev规则绑定硬盘
    udev规则绑定硬盘#lsblk-oNAME,MODEL,SERIALNAMEMODELSERIALsdaSamsungSSD860S3YLNM0NC12424A├─sda1├─sda2└─sda3├─cl-root└─cl-swapsdbSamsungSSD860S3ZBND0NC04099A└─sdb1sdcSamsungSSD......
  • WPF TranslateTransform +=deltaX +=deltaY
    <Windowx:Class="WpfApp136.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • WPF初学习(一)
    控件模板控件模板又包括ControlTemplate和ItemsPanelTemplateControlTemplate(控件模板)不仅是用于来定义控件的外观、样式,还可通过控件模板的触发器(ControlTemplate.Triggers)修改控件的行为、响应动画等。样式定义了一些基础的样式,背景颜色、字体颜色、边框大小、垂直水......
  • WPF界面反编译神器Snoop使用介绍
    Snoop介绍Snoop是一款开源的WPF监视工具,它能够监视或浏览任何正在运行的WPF应用程序的可视化、逻辑和自动化树(无需调试器),还可以更改属性值、查看触发器、在属性更改时设置断点等。项目地址:https://github.com/snoopwpf/snoopwpf 运行可以到githubrelease下载已经编译......
  • DevExpress WPF中文教程:Grid - 如何向项目添加GridControl并绑定到数据
    DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。无论是Office办公软件的衍伸产品,还是以数据为中心......
  • C#WPF数字大屏项目实战10--不良指标分页
    1、区域划分2、区域布局 3、视图模型  4、控件绑定5、运行效果 走过路过,不要错过,欢迎点赞,收藏,转载,复制,抄袭,留言,动动你的金手指,财务自由......
  • WPF datagrid scrolldown and change the marked the location in canvas
    <Windowx:Class="WpfApp134.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • 一款WPF的精简版MVVM框架——stylet框架(MVVM绑定、依赖注入等)
    今天偶然知道一款叫做stylet的MVVM框架,挺小巧的,特别是它的命令触发方式,简单粗暴,让人感觉很巴适,现在我做一个简单的demo来顺便来分享给大家。本地创建一个WPF项目,此处我使用.NET8来创建。然后引用stylet最新的nuget包。 然后删掉App.xaml里面自带的启动项删掉以后: sty......