【WPF】二、样式基础

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <!--这是基础的模板其他控件可以引用-->
        <Style x:Key="BaseText" TargetType="TextBox" >
            <Setter Property="FontSize" Value="18"></Setter>
            <Setter Property="Foreground" Value="White"></Setter>
            <Setter Property="Background" Value="LightBlue"></Setter>
        </Style>
        <!--这是引用后的控件-->
        <Style x:Key="inputText"  TargetType="TextBox"  BasedOn="{StaticResource BaseText}">
            <Setter Property="Text" Value="请输入身份证号"></Setter>
        </Style>
        <!--这是一个button控件样式-->
        <Style x:Key="clickButton" TargetType="Button">
            <Setter Property="FontSize" Value="18"></Setter>
            <Setter Property="Content" Value="查询"></Setter>
            <Setter Property="Foreground" Value="White"></Setter>
            <Setter Property="Background" Value="Orange"></Setter>
        </Style>

    </Window.Resources>
    <Grid>
        <StackPanel>
            <Label>33</Label>
            <!--控件样式实现方式-->
            <TextBox Style="{StaticResource inputText}"></TextBox>
            <Button Style="{StaticResource clickButton}"></Button>
        </StackPanel>
        
    </Grid>
</Window>

 

posted @ 2022-08-26 22:09  xxxyz  阅读(42)  评论(0)    收藏  举报