By changing the window template all controls are gone
I want to change my window template, for example:
<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>
which causes the Windows controls to become invisible. How do I keep them visible?
+1
a source to share
1 answer
You need to include the element in your template to tell the Window where its content will be displayed. The ContentPresenter does the magic for you: it will display the contents of the window anywhere you insert into the tree.
If you want normal content to appear 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>
+5
a source to share