Caliburn Micro Guard Methods not evaluating on property change

后端 未结 3 1971
旧时难觅i
旧时难觅i 2021-02-18 23:08

I\'ve been playing with the Caliburn Micro MVVM framework and am having some problems with guard methods.

I have a view model:

public class MyViewModel :         


        
3条回答
  •  死守一世寂寞
    2021-02-18 23:33

    Ok I figured it out. I didn't realise that you have to fire the guard method notification, thought the framework did that, but it makes sense.

    So I change my property setter to:

    public DateTime? Date
    {
       get
       {
          return this.date; 
       }
       set
       {
          this.date = value;
          this.NotifyOfPropertyChange(() => Date);
          this.NotifyOfPropertyChange(() => CanCalculate);
       }
    }
    

    and changed my CanCalculate method to a property:

    public bool CanCalculate
    {
        get
        {
            return this.Date.HasValue;
        }
    }
    

    And all works fine now :)

提交回复
热议问题