SilverLight 后台定义控件样式Style
2012-03-01 15:53
281 查看
<Application xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
x:Class="MyApp.App">
<Application.Resources>
<Style x:Name="MyTextBoxStyle" TargetType="TextBlock">
</Style>
</Application.Resources>
</Application>
如何通过后台编码将这一样式应用到控件上呢?其实很简单,只需要一行代码即可:
textBlock.Style = Application.Current.Resources["MyTextBoxStyle"] as Style;
上面的样式是定义在App.xml中的全局样式,如果我们需要应用定义在页面中的样式,只需要稍作调整,代码如下:
textBlock.Style = Resources["MyTextBoxStyle"] as Style;
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
x:Class="MyApp.App">
<Application.Resources>
<Style x:Name="MyTextBoxStyle" TargetType="TextBlock">
</Style>
</Application.Resources>
</Application>
如何通过后台编码将这一样式应用到控件上呢?其实很简单,只需要一行代码即可:
textBlock.Style = Application.Current.Resources["MyTextBoxStyle"] as Style;
上面的样式是定义在App.xml中的全局样式,如果我们需要应用定义在页面中的样式,只需要稍作调整,代码如下:
textBlock.Style = Resources["MyTextBoxStyle"] as Style;
相关文章推荐
- SilverLight学习笔记--如何在xaml文件中操作用户在后台代码定义的类(2)--示例篇:创建一个登录控件(原创)(转载本文请注明出处)
- Silverlight样式(Style)的定义与引用
- Silverlight Style (二) 自定义样式在后台代码中应用
- 【收藏】Silverlight Style (二) 自定义样式在后台代码中应用
- WPF后台设置xaml控件的样式System.Windows.Style
- silverlight .net后台 设置visifire控件图表样式 属性说明
- 后台设计控件的样式Style
- SilverLight在后台改变控件的样式
- Silverlight样式(Style)的定义与引用
- android中控件的style中主题样式定义
- 【收藏】Silverlight Style (二) 自定义样式在后台代码中应用
- Android学习笔记(六) —— 样式化的定型对象 — Style样式的定义
- 一步一步学Silverlight 2系列(8):使用样式封装控件观感 (转)
- 后台动态添加控件及设置样式
- 一步一步学Silverlight 2系列(8):使用样式封装控件观感
- Flex中如何通过borderStyle和borderSides样式设置NumericStepper控件特定边框(上下左右边)的例子
- 用js动态控制一个控件的style样式
- [转]silverlight中定义样式
- Silverlight样式定义
- 图表控件chartingToolkit去除图例说明区域以及数据点的样式定义