0

My project using MVVM design pattern using Prism and Unity, basically following the famous Prism video by Brian Lagunas, but the video didn't mention how to create/use partial view, User Control used in other User Controls.

I'm trying to create custom partial view(UserControl) can be reused in other page (User Control). For example, a View contains a "Browse" button Binding SelectFileCommand and Publish the file Path when done. If I have two of this View in one page, how can I subscribe to the correct command? Both Commands called same name.

For using Partial View:

Register View Type in Module like this:

container.RegisterType<IPartialView, PartialView>();

and use the view directly in page like this:

<views:PartialView DataContext="{Binding PartialViewModel}" />

I'm not sure if this is the correct way to implement Prism MVVM pattern. Please let me know if this is the wrong idea, and how to implement these kind of Partial View.

Thanks a lot.

Winter Winter
  • 173
  • 2
  • 11

1 Answers1

0

I'm not sure I understand what you need but I'll give it a try.

If your partial view is in another module, first, you can't use elsewhere than in this same module. You could use some IPartialView, but I'm not sure this is needed here, Prism gives much simpler solutions.

The simplest way to do what I think you want to do would be to have a region where you want to have your partial view. You would use RegisterViewWithRegion in the module definition to register the PartialView against the corresponding region(s). That way, if you have this partial view several times, you will have several regions with the same name, and only one registration of PartialView in the module. Just give the right DataContext to each region.

Arhiman
  • 227
  • 1
  • 6
  • Hi, What I was looking for is, I have a view with similar command actions, I was thinking to create one or two partial views to replace all command actions, so all partial views will be in same module. – Winter Winter May 20 '13 at 22:41
  • And each one of them will return a result object, for example, a browse button, I can put 2 or 3 in my view, and each of them return a file path. So question the view have one Command, and publish same result, when I have multiple of them in one main view, how to subscribe the result? Same partial view, same command, how to differentiate? Or maybe this whole thing is a bad idea. – Winter Winter May 20 '13 at 22:50