我試圖綁定到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