Savvas Sopiadis
Savvas Sopiadis

Reputation: 8223

How to implement a modal like behavior

I 'm running currently into a situation for which i cannot find a solution:

In a WPF application i 'm opening several user controls in a tabcontrol. So every tabitem has different things loaded(e.g. customer,supplier, article, warehouse,...).

In the customer tabitem i want to delete the selected customer, so i want a pop up to show up with a confirmation "do you want to delete the customer?" which is MODAL to THIS tabitem, letting the user the possibility to select another tabitem eg. the supplier. The user can select the supplier tabitem where she can do whatever she wants,... but coming back to the customer tabitem she still sees the dialog box.

How can this be implemented using MVVM techniques?

Thanks in advance

Upvotes: 0

Views: 416

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564791

Make the "modal window" a UserControl. Have it's visibility tied to a property in the ViewModel.

You can then place the UserControl in the grid along with the tab content, but with a higher Z-index. When the property is swapped to true in the VM, the "modal window" UserControl will become visible, and completely cover the tab content. This prevents any manipulation within that tab, without preventing the tab switching.

This, BTW, is a similar technique to the one Josh Smith used in Advanced MVVM for all of his dialogs. (There are some definite differences, since he wasn't dealing with tabbed items, etc... but the core concept is the same.)

Upvotes: 2

Related Questions