初学WPF,关于如何在后台中寻找样式资源代码如下:
1、Style xxStyle=(Style)this.FindResource("NorBtnStyle");
btnName.Style=xxStyle;
2、btnName.Style=FindResource("NorBtnStyle") as Style;
---应用资源文件中的图像
PathGeometry pg=this.FindResource("wavePath") as PathGemoetry;
资源文件MainStyle.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="NorBtnStyle" TargetType="{x:Type Button}">
...
</Style>
<PathGeometry x:Key="wavePath" ...>
...
</PathGeometry>
</ResourceDictionary>
注:Silverlight的样式资源代码跟WPF不一样,一般如下写法:
btnName.Style = Resources["underlineBtnStyle"] as Style;