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


本文摘自PHP中文网,作者一个新手,侵删。

1.隐式方法,通过仅指定 Style 的 TargetType。(设置全部的Button样式)


1

2

3

4

5

6

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 属性


1

2

3

4

5

6

7

8

9

<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

2

3

4

5

6

7

8

9

10

//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.使用样式文件进行调整样式

阅读剩余部分

相关阅读 >>

c# 中guid生成格式有哪些方法

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

memorycache问题修复的解决方法

c#中关于扩展方法的实例分析

使用一个wpf程序起调一个uwp程序

克隆对象的方法实例教程

有关.net mvc长轮询的实现方法

task用法之启动方法实例

.net winform的gdi双缓冲的实现方法_实用技巧

分享html元素调用服务器实例

更多相关阅读请进入《方法》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...