简体   繁体   中英

WPF - How to hide a button on ChildWindow when I call it from MainWindow using MVVM

I have two WPF forms ( MainWindow and ChildWindow ) with their different viewModels already in place ( MainViewModel and ChildViewModel ) to manage the events.

When I click the menu item on MainWindow to open the ChildWindow , I want a specific button to be hidden in the ChildWindow .

How can I perform this using MVVM?

On the child window's VM

  1. Put a Boolean property (with the change notification as with other properties on the VM) which when true will show the button and false hide it.
  2. On the button's Visibility property bind to the VM property and use a Boolean to visibility converter (has one already been defined in the page's resource, of so use it) to take the true/false value and change it to a visibility value.

This article doesn't get into the full blown history of MVVM, but it provides a basic example to help you with MVVM and binding:

Xaml: ViewModel Main Page Instantiation and Loading Strategy for Easier Binding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM