我该如何申请一个活力四射的风格在code运行时? [英] How do I apply a dynamic style in code at runtime?

查看:119
本文介绍了我该如何申请一个活力四射的风格在code运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要申请一个样式code IKE这样的:

  TextBlock.Style = TryFindResource(myStyle的)的风格;
 

这将动态更新时资源字典被改变(即皮肤代替在运行时)。换句话说,我需要相当于使用动态资源是这样的:

 < TextBlock的风格={DynamicResource myStyle的}/>
 

解决方案

尝试使用<一个href="http://joshsmithonwpf.word$p$pss.com/2007/06/29/how-to-set-a-property-to-a-dynamicresource-reference-in-$c$c/">SetResourceReference.

  textBlock.SetResourceReference(TextBlock.StyleProperty,myStyle的)
 

I need to apply a style in code ike this:

TextBlock.Style = TryFindResource("MyStyle") as Style;

that will be updated dynamically when the resource dictionary is changed (i.e. skin is replaced at runtime). In other words I need the equivalent to using a dynamic resource like this:

<TextBlock Style="{DynamicResource MyStyle}" />

解决方案

Try using SetResourceReference.

textBlock.SetResourceReference(TextBlock.StyleProperty, "MyStyle")

这篇关于我该如何申请一个活力四射的风格在code运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆