[英]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.