后台调用样式问题
前台页面: <Style x:Key="treeview_picture" TargetType="sdk:TreeViewItem">
<Setter Property="Header" >
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="/SilverlightApplication19;component/Images/文件夹.png"></Image>
<TextBlock Text="文件管理" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
后台调用: TreeViewItem tvi = new TreeViewItem();
tvi.Style = App.Current.Resources["treeview_picture"] as Style;
为什么调用不了样式呢~?
[解决办法]
最笨的办法,给这个textblock加一个name属性
然后后台遍历可视树,根据这个name找到这个textblock就行了
[解决办法]
在前台,我们可以通过语句
Style="{StaticResource btnStyle}"
来绑定样式,在后台中对应的语句是:
ButtonTest.Style = App.Current.Resources["btnStyle"] as Style;
或者:
ButtonTest.Style = System.Windows.Application.Current.Resources["btnStyle"] as Style;
请参考:
http://silverlightchina.net/html/tips/2013/0204/21823.html