我正在使用 Silverlight CheckBox 和 RadioButton,并且有以下场景:
数据上下文:
public class ViewModel : INotifyPropertyChanged
{
bool isChecked;
public bool IsChecked
{
get { return isChecked; }
set
{
isChecked = value;
InvokePropertyChanged("IsChecked");
}
}
public void OnCheckBoxChecked()
{
// This function is run when the CheckBox Checked event triggers
}
public event PropertyChangedEventHandler PropertyChanged;
void InvokePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
看法:
<UserControl x:Class="KSLog.Frontend.Features.CaseOverview.Views.CheckBoxView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" Checked="HandleInViewModel"/>
</Grid>
</UserControl>
当您单击复选框时,会在通过绑定更新“ViewModel.IsChecked”之前运行“ViewModel.OnCheckBoxChecked”。尽管“CheckBox.IsChecked”已更新。
这是错误还是设计选择?这对我来说似乎是一个错误!否则事件应该被称为检查?:)
有没有人想过为什么会这样?