How to use ContentPresenter on Window?

Posted by mybrokengnome on Stack Overflow See other posts from Stack Overflow or by mybrokengnome
Published on 2010-04-12T20:48:51Z Indexed on 2010/04/12 20:53 UTC
Read the original article Hit count: 217

Filed under:
|
|

I've got a ResourceDictionary file that contains a bunch of resources to define elements of my UI. Including one for my DialogWindows, which will just be Windows.

    <Style x:Key="DialogWindow" TargetType="{x:Type Window}" >
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="WindowStyle" Value="None" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Window}">
                <Grid Background="{StaticResource SunkenBackground}">
                    <StackPanel Margin="20,20,20,20" Background="{StaticResource SunkenBackground}">
                        <AdornerDecorator>
                            <ContentPresenter/>
                        </AdornerDecorator>
                    </StackPanel>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

As you can see every DialogWindow should have a grid and a stackpanel, and then the content goes inside there. I've added the file to my App.xaml, and on one of my dialog windows I added Style="{StaticResource DialogWindow}".

So the question is: Now that I have my Template set up for a window, and things are actually styled properly once I've added the StaticResource, what tags do I use to wrap my content in inside of my DialogWindow? I tried wrapping them inside Grid, but that just breaks the layout. If I wrap them inside a StackPanel, they look correct, but then I've got 2 StackPanels and a Grid, when if I didn't include the template I could just have 1 StackPanel and a Grid (I realize I could just take the stackpanel out of the template and do it for every DialogWindow, but that doesn't seem like a good solution).

Thanks!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about xaml