0

I need to show a similar-looking dialog in two different places in my application, one place as a modal dialog box and one place embedded into another menu.

From my limited understanding of WPF, it looks like Styles would allow me to write a single UserControl and customize its colors and fonts for both scenarios. However the changes are a bit more extensive, some of the element positions (for example, TextBox) are in different relative positions.

I am not sure if this can be done with Styles, or if there is a more appropriate way to do this in WPF. Worst case, I can write two completely different UserControls, but that is very bad in terms of maintainability so I'd like to avoid it.

Locksleyu
  • 5,192
  • 8
  • 52
  • 77

2 Answers2

0

Sure you can do it with styles/templates. Just give each of the styles a key and use the key to access the right style at the right place:

<YourUserControl Style="{StaticResource firstStyle}"/>
seri
  • 324
  • 2
  • 11
  • This ain't gonna help him. He want some setter values to be customized based on the placement of UserControl for which he needs some modification in its style. – Rohit Vats Oct 21 '11 at 14:23
  • I don't think I need to base it on the placement of UserControl, rather I can do as Dennis recommends and set a different style for each instance of my control. But what I am confused about is how to set the location of the controls based on a style. – Locksleyu Oct 21 '11 at 14:42
0

If you use a pattern like MVVM (I prefer MVVM Light) this is quite simple to do. You would write one ViewModel that captured all the data and behavior you wanted to expose and then create two views the way you want them, both using the same view model.

This scenario is one of the core intents behind the MVVM pattern. You're right that it is "bad" to write the behavior/plumbing twice, but the views are different, so you're not violating any re-use there.

Eric
  • 773
  • 1
  • 5
  • 9