zoukankan      html  css  js  c++  java
  • 如何在WPF中定义窗体模板

    可以在app.xaml中定义一个ControlTemplate,指定TargetType为Window
    <Application x:Class="WpfApplication1.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        StartupUri="Window1.xaml">
        <Application.Resources>
            <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>
        </Application.Resources>
    </Application>
    
    然后在窗体中可以像下面这样使用
    <Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300" Template="{DynamicResource WindowControlTemplate1}">
        
        <Button Grid.Row="1" Grid.Column="1" Content="Hello,World"></Button>
        
    </Window>
    
  • 相关阅读:
    2018-2019-2 网络对抗技术 20165317 Exp5 MSF基础应用
    2018-2019-2 网络对抗技术 20165317 Exp4 恶意代码分析
    2018-2019-2 网络对抗技术 20165317 Exp3 免杀原理与实践
    2018-2019-2 网络对抗技术 20165317 Exp2 后门原理与实践
    2018-2019-2 20165317《网络对抗技术》Exp1 PC平台逆向破解
    2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165317
    2018-2019-2 20165308《网络对抗技术》Exp9 Web安全基础
    2018-2019-2 网络对抗技术 20165308 Exp 8 Web基础
    2018-2019-2 20165308网络对抗技术 Exp6:信息收集与漏洞扫描
    20165308『网络对抗技术』Exp5 MSF基础应用
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1643676.html
Copyright © 2011-2022 走看看