MVVM Main window control bind from child user control

后端 未结 2 500
死守一世寂寞
死守一世寂寞 2020-12-20 03:15

I’m very new to MVVM and getting my first POC done now. However, I have been hitting my head to get one issue resolved for 2 days. Thought of explaining to you guys may help

2条回答
  •  北海茫月
    2020-12-20 03:51

    I may be misunderstanding your needs here, but it sounds like you have a TextBlock in the MainWindow that needs to be updated in response to something that occurs in and with data supplied by the ChildWindow. Assuming that's what you're trying to do then I think there are a few different ways that you could do it. In particular, you could use an attached event.

    http://msdn.microsoft.com/en-us/library/bb613550.aspx

    The technical explanation is a bit lengthy, so I'll leave it to MSDN to do that, but the short explanation is simply that it's just an event that will be raised from your child window and handled by your MainWindow. The bonus here is that it will pass in your ChildWindowViewModel as the DataContext.

提交回复
热议问题