wrfccl
2015-12-16 02:06
采纳率: 100%
浏览 1.7k
已采纳

WPF 窗体模板调用无效怎么解决?

如下是我自己定义的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>

运行结果却是黑屏(如下图),模板根本没有起作用怎么解决啊?
调用模板样式后的效果

如下是没调用窗体模板的效果:
没有调用模板样式的效果

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题