Binding ViewModel to multiple windows

后端 未结 4 811
醉话见心
醉话见心 2021-02-14 21:37

I\'m re-writing my windows forms project that does scoring for sheep shearing events (don\'t ask, its a huge sport in New Zealand) from vbnet to wpf c# and have struck a problem

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-14 22:07

    I suspect that each window is creating its own instance of the ViewModel. You could try the following:

    public MainWindow()
    {
        InitializeComponent();
    
        SheepViewModel svm = new SheepViewModel();
        this.DataContext = svm;
    
        ScoreScreen SW = new ScoreScreen();
        SW.DataContext = svm;
        SW.Show();        
    }
    

提交回复
热议问题