Hello all
I have a few dockpanes that should share the same status ruler within then (show the step we are in).
The best way to do it is to create user control and use it in all dock pane and set the status within it in the code.
I created a WPF user control but I cannot find the way to put it in a few different dockpanes.
Every dock pane is a user control too...
I found the "ReusableUserControl" (under Framework) example but I am not clear how to apply it in my case.
Does anybody have a simple explanation how to do it?
Thanks
Mody, to answer the question of how to use a user control "within" a user control I recommend doing a google on "WPF DataTemplate" and "WPF ContentPresenter" and going on stackoverflow- You will find lots of examples there. To help you get going here are three options I put together but there many different permutations and possibilities in WPF...you will need to evaluate which is best for your situation.
Alright, so, that said, assume this is your control (xaml not shown)
Option 1. Simply add a reference to it in your dockpane. This is the easiest:
Option 2: Use something called a content presenter. A content presenter is basically a placeholder into which you can put any content - in this case your user control. Bind it to a property of type UserControl or FrameworkElement (or even "ModyView" - our specific custom UserControl type if you prefer)...
and in the dockpane view model....when we set the property, the content will be shown.
Option 3 Assume you have a non-visual class that you want to set as the content and you will be using your user control to render it. For example, a non-visual class called "StatusRuler"...
The dockpane has a content presenter the same as option 2 but we now bind it to a property of type of "StatusRuler" (see the bottom code window)....the non-visual class....rather than a user control directly. This is our updated dockpane.
Next we add a data template to the dockpane view - a data template links or associates our user control "ModyView" with the non-visual type "StatusRuler". Usually, the data template goes in your dockpane resources but it can go in a separate resource dictionary or even the resources of the ContentPresenter itself. It just depends on whether the data template is something you want to re-use on multiple dockpanes (without copy/pasting) or not. When you set the ContentPresenter to be an instance of the non-visual type "StatusRuler", the data template kicks in to tell the ContentPresenter to use an instance of the user control "ModyView" to show it. Et voila.