0

我有以下窗口定义

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

在设计器中产生以下窗口

控制模板前的窗口

当我从模板定义中删除注释时,网格似乎没有呈现在同一位置?我在这里想念什么?

在此处输入图像描述

4

1 回答 1

1

我已经在VS2010 Designer中看到过这种行为几次,我很确定这是一个错误。

使用空的Template,没有要渲染的内容,因此您根本看不到Grid。当您删除 ControlTemplate 中的注释时,效果很可能是VS2010 Designer每次您为 a设置模板Window时都会发生的错误,因此我认为您实际上并没有遗漏任何内容。
即使您使用在Expression Blend中创建的默认窗口模板,它也会发生

这是使用默认模板的VS2010 DesignerExpression Blend 4之间的比较,Window如您所见,这看起来确实像一个错误

在此处输入图像描述

注意:当您使用为 a 设置模板时会发生完全相同的事情GroupBox,即使您设置的 ControlTemplate 与默认模板相同

于 2011-02-05T22:58:00.603 回答