1
我目前正在嘗試使ViewA中的滑塊更改viewA和viewB中文本的字體大小。我已正確綁定了所有內容,但在更改字體大小屬性時,委派命令未調用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