WPF中如何使用全球资源? [英] How do I use global resources in WPF?

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

问题描述

我有一个WPF应用程序,我想用一些静态的资源。我创建了一个资源库的XAML文件,其中包含的资源。我也通过属性面板中添加一个字符串到项目的资源。

I have a WPF application which I would like to use some static resources in. I have created a Resource Library XAML file which contains a resource. I have also added a string into the Resources of the project through the Properties panel.

我以为我可以只使用这些资源,结合前pression:

I assumed I could just use these resources with the binding expression:

{StaticResource ResourceName}

但是,Visual Studio是告诉我的资源都没有发现。我一定要包括某种形式的在我的XAML参考?我只看到这些例子包括本地资源,如:

But visual studio is telling me the resources are not found. Do I have to include some form of reference in my XAML? The examples I have seen only include resources locally such as:

<Window.Resources>, <Page.Resources> etc

我不希望在本地包括资源,因为我希望他们能够提供给应用程序的多个部分。

I don't want to include the resources locally because I want them to be available to multiple parts of the application.

推荐答案

,把它们放进App.xaml中:)

Put them in the App.xaml :)

在每一个WPF应用程序中有一个   的App.xaml(及其相应code   文件App.xaml.cs或App.xaml.vb)   其中工程作为一个全球性的文件   应用广泛的声明。您可以   使用此文件来声明一个常量   外观和感觉在你的应用程序。   例如,你可以声明默认   红色背景中的所有按钮   应用程序。

In each WPF application there is an App.xaml (and its corresponding code file, App.xaml.cs or App.xaml.vb) which works as a global file for application wide declarations. You can use this file to declare a constant look and feel across your application. For example you can declare a default red background for all buttons in an application.

<一个href="http://www.microsoft.com/emea/msdn/thepanel/en/articles/introduction_wpf.aspx">http://www.microsoft.com/emea/msdn/thepanel/en/articles/introduction_wpf.aspx

这篇关于WPF中如何使用全球资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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