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.csApp.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}" />

更多相关文章

  1. C#对Word文档的创建、插入表格、设置样式等操作实例
  2. 详细介绍使用XML资源文件来定义颜色,样式等
  3. 使用CSS样式表格式化XML文档的详情介绍
  4. 具体分析微软的xml解析器
  5. jQuery自定义样式下拉框,支持分组、多选和搜索
  6. 继 GitHub 后微软又收购了 npm
  7. 想来微软实习吗?
  8. 尝鲜!微软首个AI量化投资开源平台Qlib上手体验!
  9. 如何用Python快速优雅的批量修改Word文档样式?

随机推荐

  1. JVM 面试题解答(40道全)
  2. 到底什么是脏读和幻读?为啥网上答案不一?
  3. 报表的各种坑...
  4. 常用 Git 指令整理
  5. Spring 的核心特性
  6. CCNP(ISCW)实验:用SDM配置GRE OVER IPSEC
  7. Spring-IoC
  8. 自建 GitLab,却玩到了 VMware
  9. Spring bean 依赖查找
  10. 这波 JVM 面试题解答,绝对给你面试加分