1、内联样式
<TextBlock FontSize="20" Foreground="Blue">好啊</TextBlock>

2、页面样式
<Button Height="20" Margin="0,78,445,213>按钮1</Button>
<Button Width="50" Height="20" Margin="0,116,453,175">按钮2</Button>

<Window.Resources>
<Style TargetType="Button" x:Key="MyStyle">
<Setter Property="Foreground" Value="Blue"></Setter>
<Setter Property="FontSize" Value="30"></Setter>
</Style>
</Window.Resources>

应用特性名称样式:
在样式中添加x:key属性
<Style TargetType="Button" x:Key="MyStyle">
<Setter Property="Foreground" Value="BlanchedAlmond"></Setter>
<Setter Property="FontSize" Value="30"></Setter>
</Style>

然后应用该样式 <Button Height="20" Margin="0,78,445,213" Style="{StaticResource MyStyle}">按钮1</Button>

3、全局样式
在App.xaml中添加
<Application.Resources>
<Style TargetType="Button" x:Key="MyStyle">
<Setter Property="Foreground" Value="Blue"></Setter>
<Setter Property="FontSize" Value="30"></Setter>
</Style>
</Application.Resources>

4、外部样式
新建Dictionary1.xaml文件
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button" x:Key="MyStyle">
<Setter Property="Foreground" Value="Blue"></Setter>
<Setter Property="FontSize" Value="30"></Setter>
</Style>
</ResourceDictionary>

在引用页面添加
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>

WPF 四种样式的更多相关文章

  1. UITableViewCellStyle 四种样式

    四种样式如下:

  2. WPF 四种尺寸单位

    原文:WPF 四种尺寸单位 像素 px 默认单位可以省略 厘米cm 英寸 in 点 pt 1in = 96px 1cm=96/2.42px 1pt=96/72px

  3. CSS 四种样式表 六种规则选择器 五种常用样式属性

    新的html程序要在VS中编写了,在vs中安装ASP.NET和Web开发,并用ASP.NET Web 应用程序(.NETFramework)创建一个网页程序.添加一个html页 后面的代码都是在htm ...

  4. CSS的四种样式

    行内式CSS样式 在标签内部使用的样式 <div id="one" style="width:50p"></div> 内嵌式CSS样式 ...

  5. Css四种样式

    1. 2 3 4 5 6.

  6. a 标签的四种样式

    在支持 CSS 的浏览器中,链接的不同状态都可以不同的方式显示,这些状态包括:活动状态,已被访问状态,未被访问状态,和鼠标悬停状态.分别如下设置: a:link {color: red} /* 未访问 ...

  7. Python中四种样式的99乘法表

    1.常规型. #常规型 i=1 while i<=9: j=1 while j<=i: print(''%d*%d=%2d''%(i,j,i*j),end='') i+=1 #等号只是用来 ...

  8. HTML5样式和列表、CSS链接的四种状态

    一.HTML5样式 1.标签: <style>:样式定义: <link>:资源引用: 2.属性: type="text/css":引入文档类型: rel=& ...

  9. CSS02--四种样式、背景、文本、链接状态、表格样式

    接上面的“CSS01”,我们接着来说一下样式.很多人不知道的是一个HTML元素有四种样式,分别是浏览器默认样式.外部样式.内部样式.内联样式,而它们的优先级是越来越高的,后面的样式会覆盖前面的样式.多 ...

随机推荐

  1. LoadRunner 函数之lr_xml_find

    实例如: char *xml_input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>&qu ...

  2. EF唯一索引

    this.Property(p => p.Name) .IsRequired() .HasMaxLength()) .HasColumnAnnotation("Index", ...

  3. RDBMS DML DDL

    RDBMS RDBMS 指的是关系型数据库管理系统. RDBMS 是 SQL 的基础,同样也是所有现代数据库系统的基础,比如 MS SQL Server, IBM DB2, Oracle, MySQL ...

  4. 每日学习笔记:js中可以直接用id名调用的问题?

    在JavaScript中,标准的id选择器调用语法是: document.getElementById('myid').style.width = pc + "%"; 但是,今天发 ...

  5. js自动闭合html标签,自动补全html标记

    假如我有一个DIV,如果没有闭合后面的样式都会乱了,这样的代码可能会影响后面的样式,我希望用js去自动闭合这种没有闭合的标签: 代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

  6. Android Studio的配置问题——Intel HAXM is required to run this AVD,VT-x is disabled in BIOS;

    Intel HAXM is required to run this AVD,VT-x is disabled in BIOS;Enable VT-x in your BIOS security se ...

  7. spark安装(实战)

    sparksql+hive :http://lxw1234.com/archives/2015/06/294.htm 1,安装scala http://scala-lang.org/download/ ...

  8. PHP正则表达式模式修饰符详解

    PHP模式修饰符又叫模式修正符,是在正则表达式的定界符之外使用.主要用来调整正则表达式的解释,提扩展了正则表达式在匹配.替换等操作的某些功能,增强了正则的能力.但是有很多地方的解释都是错误的,也容易误 ...

  9. BZOJ2982——combination

    1.题意:求 C(n,m) % 10007 ,10007是质数咯 n和m < 2000000000 2.分析:这个东西太大了,显然不能用n!的阶乘预处理的方式搞出来,也不能用递推公式搞出来 于是 ...

  10. liunx中计算机壳层

    什么是shell?shell是用C语言编写的程序.既是一种命令语言,又是一种程序设计语言.shell是一种应用程序,这个应用程序提供一个界面,用户通过这个界面访问系统内核的服务.在计算机科学中,She ...