Tony
Tony

Reputation: 12705

By changing a window template all controls are gone

I want to change my window template, eg:

<Style x:Key="SilverGreenWindowStyle" TargetType="{x:Type Window}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Grid Background="{StaticResource SilverGreenBackground}" Width="503" Height="383">
                    <Rectangle Margin="192,86,21,119" Fill="{StaticResource SilverGreenRectangleBackground}" Width="200" Height="200"/>
                </Grid>    
            </ControlTemplate>
        </Setter.Value>    
    </Setter>
</Style>

and that causes the windows controls to become invisible. How do I keep them visible?

Upvotes: 1

Views: 162

Answers (1)

Samuel Jack
Samuel Jack

Reputation: 33280

You need to include an element in your template to tell the Window where to display it's content. ContentPresenter does the magic for you: it will render the Window's content at whatever position you insert it in the tree.

If you want the regular content to display on top of the Rectangle, for example, you can do this:

<Style x:Key="SilverGreenWindowStyle" TargetType="{x:Type Window}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Grid Background="{StaticResource SilverGreenBackground}" Width="503" Height="383">
                    <Rectangle Margin="192,86,21,119" Fill="{StaticResource SilverGreenRectangleBackground}" Width="200" Height="200"/>
                    <ContentPresenter/>
                </Grid>    
            </ControlTemplate>
        </Setter.Value>    
    </Setter>
</Style>

Upvotes: 5

Related Questions