(转) silverlight 样式学习
原文地址:http://www.cnblogs.com/Joetao/articles/2074727.html
<UserControl x:Class="StyleDemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<!--
样式学习
(一)样式模板的基本知识
改变控件外观有2种方式
(1)Style
用Style的x:Key值来引用这个样式
用TargetType来声明作用的目标的类型(Button、ComboBox、Grid等Control)
通过Setter来声明作用目标的属性,每个Setter都要指定Property和Value
一个Style可以添加多个Seter
(二)样式的作用域
(1)全局样式
<Application.Resource>
</Application.Resource>
(2)局部样式
<UserControl.Resources>
</UserControl.Resources>
(3)内部样式
<Button Content="红色">
<Button.Style>
<Style TargetType="Button">
</Style>
</Button.Style>
</Button>
(三)控件模板
尽管通过属性可以改变控件的外观,但是这种改变是有限的。比喻要制作一个圆形按钮
控件模板也是样式的一个类型,对于一般样式我们的Property可以是Background、FontSize、Margin等简单属性
而对于控件模板样式的Property是Template,而Value是一个ControlTemplate
-->
<!--定义用户控件资源-->
<UserControl.Resources>
<!--Button样式1-->
<Style x:Key="buttonStyle1" TargetType="Button" >
<Setter Property="Background" Value="#ffee00"/>
<Setter Property="FontSize" Value="24"/>
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="Margin" Value="10,10,10,10"/>
</Style>
<!--Button样式2-->
<Style x:Key="buttonStyle2" TargetType="Button">
<Setter Property="Background" Value="White"/>
<Setter Property="FontSize" Value="24"/>
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Margin" Value="25,25,25,25"/>
</Style>
<!--定义模板样式1-->
<Style x:Key="templateButtonStyle1" TargetType="Button">
<!--使用模板属性-->
<Setter Property="Template">
<Setter.Value>
<!--定义模板1-->
<ControlTemplate TargetType="Button">
<Grid Cursor="Hand" Margin="20">
<Ellipse Width="150" Height="100" HorizontalAlignment="Center" VerticalAlignment="Center">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="Gold" Offset="1"/>
<GradientStop Color="White" Offset="0"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<!--
使用TemplateBinding
TemplateBinding引用按钮本身的Content属性值,这样显示的内容不是“控件模板1”,而是后面的应用控件模板样式“我的控件”作为按钮内容
-->
<TextBlock Text="{TemplateBinding Content}" FontSize="24" Foreground="Blue" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--定义模板样式1-->
<Style x:Key="templateButtonStyle2" TargetType="Button">
<!--使用模板属性-->
<Setter Property="Template">
<Setter.Value>
<!--定义模板1-->
<ControlTemplate TargetType="Button">
<Grid Cursor="Hand" Margin="20">
<Ellipse Width="130" Height="130" HorizontalAlignment="Center" VerticalAlignment="Center">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="Red" Offset="1"/>
<GradientStop Color="White" Offset="0"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<TextBlock Text="控件模板2" FontSize="24" Foreground="Blue" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Horizontal">
<!--应用样式1的按钮-->
<Button Content="蓝色" Width="150" Height="80" Style="{StaticResource buttonStyle1}"/>
<!--应用样式2的按钮-->
<Button Content="白色" Width="150" Height="80" Style="{StaticResource buttonStyle2}"/>
<Button Content="红色" Width="150" Height="80">
<!--内联样式-->
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background" Value="Red"/>
<Setter Property="FontSize" Value="24"/>
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Margin" Value="25,25,25,25"/>
</Style>
</Button.Style>
</Button>
<!--应用全局样式-->
<Button Width="200" Height="80" Content="全局样式" Style="{StaticResource buttonStyleGlobal}"/>
<!--应用模板样式1-->
<Button Style="{StaticResource templateButtonStyle1}" Content="我的控件"/>
<!--应用模板样式2-->
<Button Style="{StaticResource templateButtonStyle2}" Content="我的控件"/>
</StackPanel>
</Grid>
</UserControl>
(转) silverlight 样式学习的更多相关文章
- 11种常用css样式学习大结局滚动条与显示隐藏
滚动条展示 overflow-x: hidden;/*是否对内容的左/右边缘进行裁剪*/overflow-y: hidden;/*是否对内容的上/下边缘进行裁剪*/overflow:scroll;/* ...
- 11种常用css样式之表格和定位样式学习
table表格中border-collapse: collapse;/*表格边框是否合并*/border-spacing: 10px;/*表格边框之间的距离*/定位详情可以阅读position属性值4 ...
- 11种常用css样式之鼠标、列表和尺寸样式学习
鼠标cursor常见样式crosshair;/*十字形状*/cursor:pointer;/*小手形状*/cursor:wait;/*等待形状*/cursor:text;/*默认 文本形状*/curs ...
- mono for android 自定义titleBar Actionbar 顶部导航栏 修改 样式 学习
以前的我是没有做笔记的习惯的,学习了后觉得自己能记住,但是最近发现很多学的东西都忘记了,所有现在一有新的知识,就记下来吧. 最近又做一个mono for android 的项目 这次调整比较大,上次做 ...
- Silverlight 样式的灵活使用
众所周知,Silverlight将界面设计与代码实现分开.即便如此,如果不能灵活地运用样式Style,开发的效率依然会比较低.比如,针对类似的TextBlock,你可能需要反复地在设计器xaml中复制 ...
- Silverlight Telerik 学习之主题的设置
Telerik控件版本:RadControls for Silverlight Q1 2013 当前的Telerik Silverlight 控件支持以下主题 Office Black - 这是默认主 ...
- Silverlight 2学习笔记一:初识Silverlight
Silverlight,问世至今已有好一段时日了,向来只是只闻其名,不知其实,今天终于对Silverlight有了点初步的了解. 一.Silverlight是什么?Sliverlight是基于.NET ...
- 【转】RadControls for Silverlight(学习2-RadDataPager)
引用地址:http://www.cnblogs.com/forrestsun/archive/2011/05/15/2046894.html <Grid x:Name="LayoutR ...
- 【转】RadControls for Silverlight(学习1-GridView)
引用:Telerik(官 网:http://www.telerik.com/)是保加利亚的一个软件公司,专注于微软.Net平台的表示层与内容管理控件.我们提供高度稳定性和丰富性能的组件产品,并可应用在 ...
随机推荐
- Facade设计模式
Facade模式 Facade模式要求一个子系统的外部与其内部的通信必须通过一个统一的Facade对象进行.Facade模式提供一个高层次的接口,使得子系统更易于使用. 就如同医院的接待员一样,Fac ...
- Android环境配置及运行helloWord案例
Android的环境搭建步骤,以及输出一个helloWorder 1:下载Android开发环境 及是: SDK adt-bundle-windows-x86_64-20140702 此时的版 ...
- 使用Axis2 插件 报错"An error occurred while completing process -java.lang.reflect.InvocationTargetException"
参考 http://blog.csdn.net/sunitjy/article/details/6793654
- cookie,session原理,以及如何使用chrome查看。
首先,先补充下chrome浏览器的使用. 1.1.php源码: <?php $cookieDomain = '.elf.com'; setcookie(, '/', $cookieDomain) ...
- jQuery操作Table tr td常用的方法
虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...
- Windows结构化异常
不错的总结: http://hi.baidu.com/wangxvfeng101/item/518f6efdab4e5616ff35820e http://www.vckbase.com/index. ...
- VS与ultraedit 正则表达式替换
ASP中把request("{param}")调用替换为requestX("{param}") VS 表达式替换(?<a>request\(&quo ...
- 使用nginx为ArcGIS Server做反向代理
1.下载nginx软件:官网地址http://nginx.org/ 2.修改conf文件夹下nginx.conf配置信息, 配置文件中以下内容: server { listen 80; s ...
- ubuntu14.04上Trac配置记录
系统环境:ubuntu14.04 (并假设Apache2服务可以正常运行) 1. 安装软件: sudo aptitude install trac python-mysqldb 2. 创建数据库Tra ...
- spark单机环境下运行一些解决问题
ERROR1.hadoop依赖 [ERROR] - Failed to locate the winutils binary in the hadoop binary path java.io.I ...