无法从XAML访问propertyResources列表



我想从同一项目内的XAML文件访问WPF项目的"Resources"属性。

  • 我添加了一个资源"Text123",并将访问修饰符设置为"Public">
  • 我将XAML文件中的命名空间声明为xmlns:p="clr-namespace:MyProject.Properties"
  • 我添加了一个从按钮内容到属性的链接作为Content="{x:Static p:Resources.Text123}"

因此,我从Visual Studio收到一条错误消息,说:名称"Resources"在命名空间"clr-namespace:MyProject.Properties"中不存在。

我能做些什么来消除这个错误?

Resources.resx文件已存在于项目中,并且看起来不错。即使在Resources.Designer.vb文件中,我也可以将我声明的Resource看作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

将默认命名空间添加到命名空间声明中,即如果您的默认命名空间是"WpfApp1",并且Resources模块在My.Resources命名空间中,则它应该是:

xmlns:p="clr-namespace:WpfApp1.My.Resources"

相关内容

  • 没有找到相关文章

最新更新