如下是我自己定義的window模板:
<ControlTemplate x:Key="WindowControlTemplate1" TargetType="{x:Type Window}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="0.93*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.21*"/>
<ColumnDefinition Width="0.79*"/>
</Grid.ColumnDefinitions>
<ContentPresenter
Grid.ColumnSpan="2"
Grid.Row="1"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
/>
<ResizeGrip
HorizontalAlignment="Right"
x:Name="WindowResizeGrip"
VerticalAlignment="Bottom"
IsTabStop="False"
Visibility="Collapsed"
Grid.Column="1"
Grid.Row="2"
/>
<TextBlock Text="My Logo" />
<TextBlock Grid.Column="1" Text="My Title"/>
<StatusBar Height="20" Grid.ColumnSpan="2" Grid.Row="2"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="ResizeMode" Value="CanResizeWithGrip"/>
<Condition Property="WindowState" Value="Normal"/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" TargetName="WindowResizeGrip" Value="Visible"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
我在前端界面如下調用:
<Window x:Class="Mes.SystemManagement.frmAction"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="系統管理" Height="650" Width="1025" WindowStyle="None" Template="{DynamicResource windowControlTemplate}" >
<Grid>
<Button Height="100" Width="100" Background="AntiqueWhite">wwwwwwwwwww</Button>
</Grid>
</Window>
運行結果卻是黑屏(如下圖),模板根本沒有起作用怎麼解決啊?
如下是沒調用窗體模板的效果:
是WindowControlTemplate1,你少了1