【问题标题】:AdornerDecorator for WPF Window changes offset of controlsWPF Window 的 AdornerDecorator 更改控件的偏移量
【发布时间】:2011-02-05 20:15:37
【问题描述】:

我有以下窗口定义

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

在设计器中生成以下窗口

当我从模板定义中删除 cmets 时,网格似乎没有呈现在相同的位置?我在这里错过了什么?

【问题讨论】:

  • 运行时如何显示?

标签: .net wpf window styles visual-studio-designer


【解决方案1】:

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

使用空的模板,没有可渲染的内容,因此您根本看不到Grid。当您删除 ControlTemplate 中的 cmets 时,效果很可能是 VS2010 Designer 中的一个错误,每次您为 Window 设置 Template 时都会发生这种情况,所以我认为您实际上并不是缺少任何东西。
即使您使用在 Expression Blend

中创建的默认窗口模板,它也会发生

下面是 VS2010 Designer 和 Expression Blend 4 使用 Window 的默认模板的比较,如您所见,这看起来确实像一个错误

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多