我试图绑定到RadioButton.IsChecked属性,它只能工作一次。在那之后,绑定无法正常工作,我不知道为什么会发生这种情况。任何人都可以帮忙吗?谢谢!RadioButton IsChecked失去约束力
这是我的代码。
C#
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
this.DataContext = new ViewModel();
}
}
public class ViewModel
{
private bool _isChecked1 = true;
public bool IsChecked1
{
get { return _isChecked1; }
set
{
if (_isChecked1 != value)
{
_isChecked1 = value;
}
}
}
private bool _isChecked2;
public bool IsChecked2
{
get { return _isChecked2; }
set
{
if (_isChecked2 != value)
{
_isChecked2 = value;
}
}
}
}
XAML:
<Grid>
<StackPanel>
<RadioButton Content="RadioButton1" IsChecked="{Binding IsChecked1}" />
<RadioButton Content="RadioButton2" IsChecked="{Binding IsChecked2}" />
</StackPanel>
</Grid>
啊,这太可怕了。我想我必须回到事件处理程序......除此之外,您还知道任何解决方法吗? – Carlo 2010-11-21 00:38:34
使用'ListBox'并将每个'ListBoxItem'设置为'RadioButton'。 http://code.msdn.microsoft.com/wpfradiobuttonlist – 2010-11-21 00:43:15