【发布时间】:2011-06-03 22:15:05
【问题描述】:
我正在使用 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.OnCheckBoxChecked”会在“ViewModel.IsChecked”通过绑定更新之前运行。虽然 'CheckBox.IsChecked' 已更新。
这是错误还是设计选择?这对我来说似乎是一个错误!否则事件应该被称为检查? :)
有人知道为什么会这样吗?
【问题讨论】:
标签: silverlight data-binding checkbox togglebutton