您的位置:首页 > Web前端 > CSS

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: