我有以下窗口定义
<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>这将在设计器中生成以下窗口

当我从模板定义中删除注释时,网格似乎不会呈现在相同的位置?这里我漏掉了什么?

发布于 2011-02-06 06:58:01
我在VS2010 Designer中看到过几次这种行为,我非常确定这是一个错误。
有了一个空的模板,就没有什么要呈现的了,所以你应该根本看不到Grid。当您删除ControlTemplate中的注释时,效果很可能是VS2010 Designer中的一个错误,每次您为设置模板Window时都会发生此错误,因此我认为您实际上不会遗漏任何东西。
即使使用在Expression Blend中创建的默认窗口模板,也会发生这种情况
下面是VS2010 Designer和使用Window默认模板的Expression Blend 4之间的比较,因此正如您所看到的,这看起来确实像是一个错误

注意:使用为GroupBox__设置模板时,即使您设置的ControlTemplate与默认模板相同,也会发生完全相同的情况
https://stackoverflow.com/questions/4909395
复制相似问题