繁体   English   中英

如何在单选按钮选中的事件上禁用Wpf DataGrid中的特定单元格

[英]How to disable particular cell in Wpf datagrid on Radiobutton checked event

我想在单选按钮选中事件中从wpf禁用Datagrid中的特定单元格。 我得到了需要禁用的单元格的行索引和列索引。

CS:

   public class InverseConverter : IValueConverter
   {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
           bool _val = (bool)value;
           return !_val;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool _val = (bool)value;
            return !_val;
        }
   }


   public MainWindow()
   {
        InitializeComponent();
        this.DataContext = this;        
   }

   public List<object> Stuff
   {
        get { return new List<object> { 1, 2, 3 }; }
   } 

XAML:

<Window>
  <Grid>
     <Grid.Resources>
        <local:InverseConverter x:Key="converter" />
     </Grid.Resources>

     <DataGrid ItemsSource="{Binding Stuff}">
        <DataGrid.Columns>
            <DataGridTemplateColumn>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <RadioButton IsChecked="{Binding Path=IsEnabled, RelativeSource={RelativeSource AncestorType=ContentPresenter}, Converter={StaticResource converter}, Mode=OneWayToSource}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>                                          
            </DataGridTemplateColumn>
        </DataGrid.Columns>

     </DataGrid>        
 </Grid>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM