ContentControl not updating

后端 未结 3 2204
一个人的身影
一个人的身影 2021-02-10 07:28

I\'m trying to have a MainWindow that is bound to the a view. I change that view in code and expect it to update in the Main Window, however that is not happening.

I hav

3条回答
  •  长发绾君心
    2021-02-10 07:48

    I think you have several muddled concepts here and they are getting in each others way.

    Firstly you aren't actually using ANY of the reactiveUI code, it never gets called. Since your get accessor implements a lazy instantiation pattern then it means the set accessor is ignored. This means that the view never notifies the property change, so you never get updates.

    I'd recommend using something more like

    private UserControl _currentControl;
    
    public MainWindowVirwModel()
    {
      CurrentControl = new HomePage();
    }
    
    public UserControl CurrentControl
    {
      get { return _curentControl;}
      set { this.RaiseAndSetIfChanged(...); }
    }
    

    In addition, this still mixes up View components i.e. HomePage, inside your ViewModel tier which will making unit testing far more difficult.

提交回复
热议问题