我有一个数据网格,其中包含 3 个包含单选按钮的 DataGridTemplateColumns。现在我想通过我后面代码中按钮的单击事件来控制 radioButtons 的“isEnabled”属性:
<DataGrid AutoGenerateColumns="False" Height="300" x:Name="dgEmps"
RowEditEnding="gridEmps_RowEditEnding" CellEditEnding="gridEmps_CellEditEnding"
FlowDirection="RightToLeft"
SelectionChanged="gridEmps_SelectionChanged">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Shift Manager">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton GroupName="{Binding EmployeeId}"
IsChecked="{Binding IsManager, Mode=TwoWay}" x:Name="dgrIsManager"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Waiter" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton GroupName="{Binding EmployeeId}"
IsChecked="{Binding IsWaiter, Mode=TwoWay}" x:Name="dgrIsWaiter"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Cook" IsReadOnly="True" x:Name="aaa">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<RadioButton GroupName="{Binding EmployeeId}"
IsChecked="{Binding IsCook, Mode=TwoWay}" x:Name="dgrIsCook"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
问题是“IsReadOnly”属性不起作用,我似乎无法从我的代码访问 radioButton 属性(甚至不能通过我在 xaml 中声明的 x:name)。我试过这个: WPF Toolkit DataGrid SelectionChanged Getting Cell Value 和许多其他教程/博客文章,但无法使其工作。有任何想法吗?