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」は更新されていますが。
これはバグですか、それとも設計上の選択ですか? それは私にはバグのようです!それ以外の場合、イベントは Checking? と呼ばれるべきでした。:)
なぜこれが事実なのか、誰でも考えましたか?