WPF Window 的 AdornerDecorator 更改控件的偏移量
我有以下窗口定义,
<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>
生成以下窗口
,它在设计器
时 我从模板定义中删除了注释,网格似乎没有呈现在相同的位置?我在这里缺少什么?
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
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 VS2010 Designer 中多次看到这种行为,并且我很确定这是一个错误。
对于空的模板,没有任何内容可以渲染,因此您根本看不到
网格
。当您删除 ControlTemplate 中的注释时,结果很可能是VS2010 Designer
中的错误,每次为Window
模板时都会发生该错误> 所以我认为你实际上并没有错过任何东西。即使您使用在Expression Blend中创建的默认窗口模板,也会发生这种情况。
这是使用VS2010 Designer和Expression Blend 4之间的比较
Window
的默认模板,如您所见,这确实看起来像一个错误注意:当您为
GroupBox
设置模板时,即使您设置的 ControlTemplate 与默认模板相同,也会发生完全相同的情况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 theVS2010 Designer
which happends everytime you set the Template for aWindow
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 bugNote: 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