【发布时间】:2019-04-11 00:33:22
【问题描述】:
我想从同一项目中的 XAML 文件访问我的 WPF 项目的“资源”属性。
- 我添加了一个资源“Text123”并将访问修饰符设置为“公共”,
- 我将 XAML 文件中的命名空间声明为
xmlns:p="clr-namespace:MyProject.Properties" - 我从按钮内容添加了指向属性的链接
Content="{x:Static p:Resources.Text123}"
因此,我从 Visual Studio 收到一条错误消息:名称“资源”不存在于命名空间“clr-namespace:MyProject.Properties”中。
我该怎么做才能摆脱这个错误?
Resources.resx 文件存在于项目中,并且似乎没问题。即使在Resources.Designer.vb 文件中,我也可以将我声明的资源视为Public ReadyOnly Property。
P.S:生成的 Resources.Designed.vb 是:
Option Strict On
Option Explicit On
Imports System
Namespace My.Resources
'This class was auto-generated by the StronglyTypedResourceBuilder
'class via a tool like ResGen or Visual Studio.
'To add or remove a member, edit your .ResX file then rerun ResGen
'with the /str option, or rebuild your VS project.
'''<summary>
''' A strongly-typed resource class, for looking up localized strings, etc.
'''</summary>
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0"), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
Public Module Resources
Private resourceMan As Global.System.Resources.ResourceManager
Private resourceCulture As Global.System.Globalization.CultureInfo
'''<summary>
''' Returns the cached ResourceManager instance used by this class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Public ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
Get
If Object.ReferenceEquals(resourceMan, Nothing) Then
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("MyProject.Resources", GetType(Resources).Assembly)
resourceMan = temp
End If
Return resourceMan
End Get
End Property
'''<summary>
''' Overrides the current thread's CurrentUICulture property for all
''' resource lookups using this strongly typed resource class.
'''</summary>
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
Public Property Culture() As Global.System.Globalization.CultureInfo
Get
Return resourceCulture
End Get
Set
resourceCulture = value
End Set
End Property
'''<summary>
''' Looks up a localized string similar to Cancel.
'''</summary>
Public ReadOnly Property Text123() As String
Get
Return ResourceManager.GetString("Text123", resourceCulture)
End Get
End Property
End Module
End Namespace
【问题讨论】:
-
您的项目是否构建并运行?
-
错误中止构建过程
-
你确定生成的类的名字是“Resource”而不是“Resources”吗?
-
这是我的问题中的错字,抱歉。当然是“资源”。我更正了问题文本。错误仍然存在
-
类的命名空间和名称是什么?
标签: wpf vb.net xaml properties