我有一个 WPF GUI,正在从磁盘加载记录。当我加载它们时,我需要根据加载的值设置一个单选按钮。
我知道这很容易,但我根本无法让它工作——有人知道所需的代码吗?
按钮在这里:
<RadioButton GroupName="Membership" Content="Probationary" Height="16" HorizontalAlignment="Left" Margin="106,194,0,0" Name="RProbationary" VerticalAlignment="Top" IsChecked="True" Checked="RProbationary_Checked" />
<RadioButton GroupName="Membership" Content="Full" Height="16" HorizontalAlignment="Right" Margin="0,195,90,0" Name="RFull" VerticalAlignment="Top" Checked="RFull_Checked" DataContext="{Binding}" />
设置它们的代码如下:
private void Window_Initialized(object sender, EventArgs e)
{
if (_name.Length != 0)
{
// blah blah lots of awesome code
// here is where we have the required value as a string which needs to be reflected
// on the GUI as a checked radio button
}
}