2016-06-09 5 views
1

현재 viewA의 슬라이더를 viewA 및 viewB의 텍스트 글꼴 크기를 변경하려고합니다. 나는 모든 것을 바운드해야하지만, 폰트 크기 프로퍼티가 변경되면 delegate 명령은 execute 메서드를 호출하지 않습니다. 이 함수를 수동으로 호출하면 모든 것이 예상대로 작동하기 때문에 코드의 한 줄이 문제 일 수 있습니다. ViewAViewModel은 다음과 같습니다.속성 변경시 위임 명령이 실행되지 않습니다.

public class ViewAViewModel : BindableBase 
{ 
    private Person _CoolChick = new Person(); 
    private int _fontSize = 12; 
    private IEventAggregator _eventAggregator; 
    public DelegateCommand UpdateSizeCommand { get; set; } 

    public Person CoolChick 
    { 
     get 
     { 
      return _CoolChick; 
     } 
     set 
     { 
      SetProperty(ref _CoolChick, value); 
     } 
    } 

    public int FontSize 
    { 
     get { return _fontSize; } 
     set { 
      Console.WriteLine(_fontSize + " => Font Size"); 
      SetProperty(ref _fontSize, value); 
      //Execute(); 
     } 
    } 

    public ViewAViewModel(IEventAggregator eventAggregator) 
    { 
     CoolChick.Age = 25; 
     CoolChick.Name = "Methalous"; 
     _eventAggregator = eventAggregator; 

     //likely the problem in this code 
     UpdateSizeCommand = new DelegateCommand(Execute, CanExecute).ObservesProperty(() => FontSize); 

    } 

    private void Execute() 
    { 
     _eventAggregator.GetEvent<UpdateEvent>().Publish(FontSize); 
    } 

    private bool CanExecute() 
    { 
     return true; 
    } 
} 
+0

바인딩이 잘못되었을 수 있습니다. Snoop과 같은 도구를 사용하여 런타임에 바인딩을 검사하십시오. – Will

답변

0

왜 그럴까요? Font 속성의 설정자에서 UpdateSizeCommand.Execute를 호출하지 않습니다. 명령 등록 정보에 Y 인드하거나 수동으로 호출하지 않으면 명령이 호출되지 않습니다.

+0

오, 이제 알겠습니다. 관찰 된 속성이 변경 될 때마다 execute 메서드가 호출 될 것으로 예상했습니다. – Methalous

관련 문제