0

I'm developing a plugin for a WPF application that has a button that launches a dialog pop-up window. So within that application, the launch of that pop-up window is literally two lines:

PluginWindow pluginWindow = new PluginWindow();
pluginWindow.ShowDialog();

The window seems to be inheriting a bunch of unwanted styling from the parent application, though. I can reset the styling on individual components using this technique:

Reset inherited WPF style?

...so my PluginWindow ends up having:

<Window.Resources>
    <Style TargetType="{x:Type TextBox}" />
    <Style TargetType="{x:Type TextBlock}" />
    <Style TargetType="{x:Type Button}" />
    <Style TargetType="{x:Type DataGrid}" />
    ...etc...
</Window.Resources>

However, the reset doesn't seem to apply to any further dialog boxes. For example, my PluginWindow has a custom confirmation dialog box (another WPF Window element) that shows up at one point, and the elements within that confirmation dialog go back to the styling from the parent application.

While I can just apply the same style-resetting technique everywhere, it seems really messy and wrong. It seems like there should just be some way of "cutting the style cord" between the parent application and the PluginWindow so that PluginWindow starts with completely-default styling, along with all of its child windows.

Is this possible to do, and if so how?

jhilgeman
  • 1,543
  • 10
  • 27
  • If i follow your description. Define a style in a resource dictionary. Use that in the resources for each of your windows. Or one window and switch out the contents by using a usercontrol instead if different windows. – Andy Nov 28 '18 at 17:18
  • Is there no way to just override the parent application's styling in a cascading manner so that my initial popup window can control all of its child elements (including child popups) from the initial popup window? – jhilgeman Nov 28 '18 at 17:38
  • A window isn't in the visual tree of some other window so no. – Andy Nov 28 '18 at 17:42
  • How is the parent application impacting its style, in that case? – jhilgeman Nov 28 '18 at 17:44
  • Because the application has scope. – Andy Nov 28 '18 at 17:45

1 Answers1

0

A window is a contentcontrol. You can therefore do

Window win = new FooWindow();
win.Content = new ChildWindowUserControl();

Put your styles in one Window ( use a better name than FooWindow ). Put your styling in that as resources. Use this for all your child windows you need one style in. Make all your different childwindows usercontrols rather than windows. Set to content of a new FooWindow ( equivalent ) and they get that style.

Andy
  • 11,864
  • 2
  • 17
  • 20