2011-01-05 5 views
1

메신저 실버 체크 박스의 RadioButton 작업, 다음과 같은 시나리오가 :바인딩이 업데이트되기 전에 트리거 된 ToggleButton checked 이벤트가 트리거 되었습니까? 곤충?

의 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'가 업데이트되었지만

이 버그와 디자인상의 차이입니까? 그것은 나에게 버그로 보인다! 그렇지 않으면 이벤트가 Checking 이라야합니까? :)

왜 이런 경우가 있는지 생각해보십시오.

답변

0

이미 비슷한 질문이 있습니다. 1. Silverlight MVVM binding updates fire in undesired order


설명 작업 물건을 얻을
  • 또한 좋은 방법
      http://www.codeproject.com/Articles/42988/Silverlight-Behaviors-and-Triggers-Making-a-Trigge.aspx

    또는 내 솔루션 (C))

     var element = FocusManager.GetFocusedElement() as TextBox; 
         if (element!=null) 
         { 
          var binding = element.GetBindingExpression(TextBox.TextProperty); 
          if (binding!=null) 
          { 
           binding.UpdateSource(); 
          } 
    
         } 
    
  • 관련 문제