0
votes

I am creating a small app using WPF, Prism and MVVM. There is a control (a loader) that I would like to reuse each time a command is being executed and I would like to place that user control on top of a certain region with some transparency. Namely, the region where the current module which calls the command.

How can I add this User control on top of a certain region from the ViewModel(is this the right place?)?

1

1 Answers

0
votes

You're correct that with Prism, the best way to do this is with regions.

Just create the region in your view, give it a unique name.

<ContentControl rgn:RegionManager.RegionName="TopRegion" />

Then, in the ViewModel use the RegionManager to add the usercontrol.

IRegion myRegion = regionManager.Regions["TopRegion"];
myRegion.Add(userControl1);

I should also point out that since this is in MVVM, you should probably want to add the usercontrol using some kind of IoC such as MEF or Unity.