C# 如果resx文件位于其他项目中,则无法使用它们
我正在.NET中开发一个WPF应用程序。我使用了很多项目,因为它有一些其他项目的共享文件,比如用于本地化的资源文件 如果resx文件和xaml文件在同一个项目中(Project1.Properties.Resources.resx),则一切正常(Project1.AccountView.xaml)C# 如果resx文件位于其他项目中,则无法使用它们,c#,.net,wpf,resx,C#,.net,Wpf,Resx,我正在.NET中开发一个WPF应用程序。我使用了很多项目,因为它有一些其他项目的共享文件,比如用于本地化的资源文件 如果resx文件和xaml文件在同一个项目中(Project1.Properties.Resources.resx),则一切正常(Project1.AccountView.xaml) 工作树 |-项目1 ||-特性 || |-Resources.resx | | ||-AccountView.xaml | | |-项目2 | ... AccountView.xaml
工作树
|-项目1
||-特性
|| |-Resources.resx
| |
||-AccountView.xaml
|
|
|-项目2
| ...
AccountView.xaml
....
这里的问题是,我在另一个项目(Project2.Views.Account.Login.resx)中有资源文件,我不能以与其他项目相同的方式在AccountView.xaml中使用这些文件(请记住,这个xaml位于“Project1”中)
Working Tree
|-Project1
| |
| |-AccountView.xaml
|
|
|-Project2
|-Views
|-Account
|-Login.resx
AccountView.xaml
<UserControl ...
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="clr-namespace:Project2.Views.Account">
...
TextBox Controls:TextBoxHelper.Watermark="{x:Static Login.Username}"/>
</UserControl>
工作树
|-项目1
| |
||-AccountView.xaml
|
|
|-项目2
|-观点
|-帐目
|-Login.resx
AccountView.xaml
...
TextBox控件:TextBoxHelper.Watermark=“{x:Static Login.Username}”/>
生成项目时的错误是:“clr命名空间:Project2.Views.Account”命名空间中不存在“Login”名称
所有resx文件都具有公共访问权限
有人知道如何解决这个问题吗?名称空间声明应该包括程序集(项目)的名称:
请注意,您所谓的解决方案实际上是一个项目。由
.sln
文件加载的项目集合称为解决方案。不过,您可以自由地将您的项目称为Solution1和Solution2,但这确实令人困惑。我接受了您的建议。谢谢。您希望在.resx中共享哪些类型的项目?字符串是可以的,但是WPF有不同的共享方式,比如说图片,它们都是字符串
Working Tree
|-Project1
| |
| |-AccountView.xaml
|
|
|-Project2
|-Views
|-Account
|-Login.resx
AccountView.xaml
<UserControl ...
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="clr-namespace:Project2.Views.Account">
...
TextBox Controls:TextBoxHelper.Watermark="{x:Static Login.Username}"/>
</UserControl>
xmlns:p="clr-namespace:Project2.Views.Account;assembly=Project2"
...
TextBox Controls:TextBoxHelper.Watermark="{x:Static p:Login.Username}"