如何在代码隐藏中引用 StaticResource? [英] How do I reference a StaticResource in code-behind?

查看:30
本文介绍了如何在代码隐藏中引用 StaticResource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 XAML 中,我是这样做的:

In XAML I do it like this:

<Button Style="{StaticResource NavigationBackButtonNormalStyle}" />

如何在代码隐藏中做同样的事情?

How do I do the same thing in code-behind?

推荐答案

页面级资源对象具有查找本地、应用级、静态和主题资源的能力.这意味着您只需执行以下操作:

The page-level Resources object has the ability to find local, app-level, static, and theme resources. This means you simply do this:

foo2.Style = this.Resources["NavigationBackButtonNormalStyle"] as Style;

祝你好运!

这篇关于如何在代码隐藏中引用 StaticResource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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