我已将以下窗口的DataContext
绑定到代码后面,以便为我提供MVVM样式
来演示此行为:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<StackPanel>
<RadioButton GroupName="test" Content="Monkey" IsChecked="{Binding IsMonkey}"/>
<RadioButton GroupName="test" Content="Turtle" IsChecked="{Binding IsTurtle}" />
</StackPanel>
</Window>
这是后面的代码:
public partial class Window1
{
public Window1()
{
InitializeComponent();
}
private bool _isMonkey;
public bool IsMonkey
{
get { return _isMonkey; }
set
{
_isMonkey = value;
}
}
private bool _isTurtle;
public bool IsTurtle
{
get { return _isTurtle; }
set
{
_isTurtle = value;
}
}
}
将断点放在
IsMonkey
和 IsTurtle
上,运行应用程序并依次选择 IsMonkey
和 IsTurtle
后,我发现它对每个控件的第一次选择有效,在第二次选择时绑定会中断,断点不再触发。请问有人能指点一下吗?