• 【再学WPF】自定义样式


    1、添加“资源字典”;

    工程名称:WpfApp1
    新建Styles文件夹;
    创建“Dictionary1.xaml”的文件;

    2、编辑样式;

        <SolidColorBrush x:Key="MainColor">#FF000000</SolidColorBrush>
        <SolidColorBrush x:Key="MainColor1">#FFFFFFFF</SolidColorBrush>
    
        <Style  TargetType="Button">
            <Setter Property="Background" Value="Blue"/>
        </Style>
    
        <Style TargetType="TextBox">
            <Setter Property="FontFamily" Value="微软雅黑"/>
            <Setter Property="FontSize" Value="23"/>
        </Style>

    3、在App.xaml中引用样式

        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="pack://application:,,,/WpfApp1;component/Styles/Dictionary1.xaml"/>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>

    4、元素上添加样式

            <Button Content="主题颜色" Width="100" Height="40" Margin="545,82,155,328"/>
            <Button Content="主题颜色" Width="100" Height="40" Margin="545,127,155,283"/>
    
            <Button Content="外部样式" Width="100" Height="40" Margin="144,270,556,140" Background="{StaticResource MainColor}" Foreground="{StaticResource MainColor1}"/>
  • 相关阅读:
    技术一定要动手做一遍才算自已的
    终于提离职了,感觉如释重负
    自我评定与学习计划
    MYSQL---INSERT...SELECT...
    MYSQL---LIMIT
    SQL---having
    MYSQL---数据定义
    CSS---Block和inline元素对比
    CSS---清除浮动
    T-SQL---分页语句
  • 原文地址:https://www.cnblogs.com/suenihy/p/11368447.html
Copyright © 2020-2023  润新知