我有一个主从WPF应用程序。“ master”是一个数据网格,“ detail”是两个单选按钮。基于行选择,将在“详细信息”部分中选中单选按钮。
我使用inttoboolean转换器按以下方式绑定单选按钮。xaml:
<StackPanel Margin="2">
<RadioButton Margin="0,0,0,5" Content="In Detail" IsChecked="{Binding Path=itemselect.OutputType, Converter ={StaticResource radtointOTSB}, ConverterParameter= 0}"/>
<RadioButton Content="In Breif" IsChecked="{Binding Path=itemselect.OutputType, Converter ={StaticResource radtointOTSB}, ConverterParameter= 1}"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
在视图模型中:
public class radtointOTSB : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int OTint = Convert.ToInt32(value);
if (OTint == int.Parse(parameter.ToString()))
return true;
else
return false;
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return parameter;
}
}
Run Code Online (Sandbox Code Playgroud)
对于datagrid中的前几个选择,我的实现效果很好。突然之间,我的单选按钮都没有被选中。
我不知道为什么会这样,欢迎提出任何建议。
提前致谢。