将字符串定义为静态资源 [英] Define a string as a static resource

查看:31
本文介绍了将字符串定义为静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法定义一个常量字符串作为整个应用程序的静态资源?

我正在运行一个 Wpf 应用程序,但没有主要的 xaml 表单.该应用程序是由单个经典 .cs 表单处理的 xaml 控件的集合.

解决方案

只需添加一个资源字典 XAML 文件,假设它命名为 Dictionary.xaml(Visual Studio 可以自动为您创建)

然后,在此字典中添加您的静态资源.

最后,在所有 XAML 控件中引用字典:

<ResourceDictionary Source="Dictionary.xaml"/></UserControl.Resources>

IS there a way to define a constant string to be used as a static resource across the whole application?

I am running a Wpf application but there is no main xaml form. The application is a collection of xaml controls handled by a single classic .cs form.

解决方案

Just add a resource dictionary XAML file, let's say it's named Dictionary.xaml (Visual Studio can create you one automatically)

Then, add your static resource in this dictionary.

To finish, reference the dictionary in all your XAML controls:

<UserControl.Resources>
                <ResourceDictionary Source="Dictionary.xaml"/>
    </UserControl.Resources>

这篇关于将字符串定义为静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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