1
IM与Silverlight的复选框和单选按钮的工作,并具有下列情形:Silverlight的ToggleButton检查事件触发绑定更新之前?错误?
的DataContext:
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.OnCheckBoxChecked'在通过绑定更新'ViewModel.IsChecked'之前运行。虽然'CheckBox.IsChecked'已更新。
这是错误还是设计选择?这对我来说似乎是一个错误!否则,该事件应该被称为检查? :)
任何人有任何想法,为什么这是这种情况?