• 技术文章 >后端开发 >C#.Net教程

    UWP中设置控件样式四种方法

    一个新手一个新手2017-10-19 10:17:31原创1446
    1.隐式方法,通过仅指定 Style 的 TargetType。(设置全部的Button样式)


    1 <Page.Resources >
    2         <Style TargetType="Button">
    3             <Setter Property="BorderBrush" Value="Lime"/>
    4             <Setter Property="BorderThickness" Value="4"/>
    5         </Style>
    6     </Page.Resources>

    2.显式方法,通过指定 Style 的 TargetType 和 x:Key 特性这一特性,然后通过使用显式键的 {StaticResource} 标记扩展引用设置目标控件的 Style 属性


    <Page.Resources >
            <Style x:Key="btnStyle" TargetType="Button">
                <Setter Property="BorderBrush" Value="Lime"/>
                <Setter Property="BorderThickness" Value="4"/>
            </Style>
     </Page.Resources>
    
    //调用
    <Button Content="跳转方法" x:Name="btnTest" Style="{StaticResource btnStyle}"/>

    3.单个样式表示


    //1.App.xaml配置文件中
    <Application.Resources>
         <SolidColorBrush x:Key="BlueBrush" Color="#FF1C90D1"/>
    </Application.Resources>
    
    //2.页面中绑定值MainPage.xaml
    <Rectangle Height="2" Width="18" Fill="{StaticResource EggshellBrush}"/>
    
    //3.获取值MainPage.xaml.cs
    App.Current.Resources["EggshellBrush"] as SolidColorBrush

    4.使用样式文件进行调整样式

    1) 创建文件夹Themes右键添加新建项visual C# àxamlà资源字典 style.xaml

    2) 在style.xaml写样式例如

    <Style TargetType="Button" x:Key="gft_FormBtm">
            <Setter Property="Background" Value="OrangeRed"></Setter>
            <Setter Property="Height" Value="50"></Setter>
            <Setter Property="FontSize" Value="16"></Setter>
            <Setter Property="Foreground" Value="White"></Setter>
            <Setter Property="HorizontalAlignment" Value="Center"></Setter>
            <Setter Property="MinWidth" Value="300"></Setter>
     </Style>

    3) 在App.xaml文件中指定资源


    <!--4.使用样式文件-->
        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="Themes/style.xaml"></ResourceDictionary>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
    </Application.Resources>

    4) 在xaml界面中使用样式文件

    1 <Button x:Name="btnSubmit"  Content="同意以上协议并注册" HorizontalAlignment="Center" Click="btnSubmit_Click" Style="{StaticResource gft_FormBtm}" />

    以上就是UWP中设置控件样式四种方法 的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:方法 四种 样式
    上一篇:有关ASP.NET中Config文件的读写讲解 下一篇:用户管理和权限和设置——mysql
    VIP课程(WEB全栈开发)

    相关文章推荐

    • 【腾讯云】年中优惠,「专享618元」优惠券!• .NET异步编程总结----四种实现模式代码总结• C#学习日记21----封装 与 访问修饰符• asp.net中3种验证码示例(数字,数字字母混和,汉字)• C# 动态加载Dll• 理解模型,视图和控制器(C#,asp.net)
    1/1

    PHP中文网