快去自定义签|

园龄:粉丝:关注:

【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>

 

本文作者:xxxyz

本文链接:https://www.cnblogs.com/xxxyz/p/16629411.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   xxxyz  阅读(37)  评论(0编辑  收藏  举报
评论
收藏
关注
推荐
深色
回顶
收起
点击右上角即可分享
微信分享提示