현재 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;
}
}
바인딩이 잘못되었을 수 있습니다. Snoop과 같은 도구를 사용하여 런타임에 바인딩을 검사하십시오. – Will