我有两个项目。一个是库,另一个是 WPF 应用程序。在我的库项目中,我创建了一个资源文件 (Resources.resx) 并在其中添加了一些字符串,并将其作为公共访问。
现在在我的 WPF 项目中,我添加了库项目的引用。现在我正在尝试在我的 XAML 控件中使用库资源文件。
这是我的代码。这里 MyApplication 是 wpf 项目, MyLibrary 是 dll 项目。
<UserControl x:Class="MyApplication.LauncherView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:p="clr-namespace:MyLibrary"
<StackPanel>
<Button Content="{x:Static p:Resources.TextFromResource}" Command="{Binding LaunchCommand}" />
</StackPanel>
</UserControl>
但最后我收到这些错误。
错误 1 名称“资源”在命名空间“clr-namespace:MyLibrary”中不存在。错误 2 找不到类型“资源”。请注意,类型名称区分大小写。