您好,欢迎访问一九零五行业门户网

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

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中设置控件样式四种方法 的详细内容。
其它类似信息

推荐信息