2011-02-05 36 views
0

抵消我已在窗口定义AdornerDecorator为WPF窗口的变化控制

<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> 

用下面的风格和模板定义

<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> 

产生以下窗口在设计以下

Window before control template

当我删除来自模板定义的评论网格似乎没有呈现在相同的位置?我在这里错过了什么?

enter image description here

+0

它在运行时如何显示? – 2011-02-05 21:08:41

回答

1

我见过的VS2010设计几次这种行为,我敢肯定这是一个错误。

随着一个空的模板,没有什么要呈现,所以你应该根本无法看到Grid。当您删除ControlTemplate中的注释时,该效果很可能是VS2010 Designer中的一个错误,每当您将模板设置为Window时,就会发生这种错误,所以我不认为您实际上错过了任何东西。
如果使用默认的窗口模板,在Expression Blend中

这里创建它甚至会发生是使用一个Window默认模板,从而可以VS2010设计师的Expression Blend 4之间的比较看,这真的看起来像一个错误

enter image description here

注:当您设置使用的模板的0123完全一样的东西happends,即使您设置的ControlTemplate与默认模板相同