如何在后面的code使用DynamicResource? [英] how to use DynamicResource in the code behind?

查看:185
本文介绍了如何在后面的code使用DynamicResource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够属性编程设置为一个动态资源。

I'd like to be able to set a property to a dynamic resource programmatically.

myControl.Property = this.Resource[key]

是不是一个有效的反应,因为如果用钥匙钥匙的资源被替换,属性不会自动更新。

is not a valid response, since if the resource with the key 'key' is replaced, the property is not updated automatically.

感谢您的回应,

推荐答案

一个静态的资源不会更新不管你做它在code或XAML。你需要一个动态的资源这一点。

A static resource won't update whether you do it in code or XAML. You'll need a dynamic resource for that.

在XAML:

<Grid x:Name="grid" Background="{DynamicResource Brush}"/>

在code:

grid.SetResourceReference(Grid.BackgroundProperty, "Brush");

这篇关于如何在后面的code使用DynamicResource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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