2011-02-05 35 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與默認模板相同