AdornerDecorator for WPF Window changes offset of controls

1.1k views Asked by At

I have the following window definition

<Window x:Class="MyWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Style="{StaticResource ShapedWindow}"
        Title="Title">
    <Grid Name="grid1" />
</Window>

with the following style and template definition

<Style x:Key="ShapedWindow" TargetType="{x:Type Window}">
        <Setter Property="AllowsTransparency" Value="True"></Setter>
        <Setter Property="WindowStyle" Value="None"></Setter>
        <Setter Property="Background" Value="Transparent"></Setter>
        <Setter Property="MinWidth" Value="300" />
        <Setter Property="MinHeight" Value="300" />
        <Setter Property="Template" Value="{StaticResource ShapedWindowTemplate}"></Setter>
</Style>

<ControlTemplate x:Key="ShapedWindowTemplate" TargetType="{x:Type Window}">
    <!--<AdornerDecorator>
        <ContentPresenter />
    </AdornerDecorator>-->
</ControlTemplate>

which produces the following window in the designer

Window before control template

When I remove the comments from the template definition the grid doesn't seem to be rendered in the same position? What am I missing here?

enter image description here

1

There are 1 answers

0
Fredrik Hedblad On BEST ANSWER

I've seen this behavior in the VS2010 Designer a couple of times and I'm pretty sure it's a bug.

With an empty Template, there is nothing to render so you shouldn't be able to see the Grid at all. When you remove the comments in your ControlTemplate, the effect is most likely a bug in the VS2010 Designer which happends everytime you set the Template for a Window so I don't think you're actually missing anything.
It'll occur even if you use the default Window Template, created in Expression Blend

Here's a comparison between VS2010 Designer and Expression Blend 4 using the Default Template for a Window so as you can see, this really looks like a bug

enter image description here

Note: The exact same thing happends when you use set the Template for a GroupBox, even if the ControlTemplate you set is identical to the default Template