我正在尝试绑定在Resources.resx中定义的名为title的静态字符串,当我运行应用程序时,我得到以下错误。在调查此论坛中的错误后,我发现生成的Resources类被标记为internal,而WPF正在尝试从另一个程序集中解析资源,因此在您的资源被标记为public之前它不会成功。同样我有一个项目,其中包含我的视图和资源定义我不需要任何朋友组装,我相信内部类可以在同一个程序集中访问。我找到了一个同事Click here的类似帖子,他建议使用ResXFileCodeGenerator。请您对此发表意见
System.Windows.Markup.XamlParseException occurred
HResult=-2146233087
Message='Provide value on 'System.Windows.Markup.StaticExtension' threw an exception.' Line number '11' and line position '9'.
Source=PresentationFramework
LineNumber=11
LinePosition=9
StackTrace:
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at TestApp.MainWindow.InitializeComponent() in ~\TestApp\TestApp\MainWindow.xaml:line 1
at TestApp.MainWindow..ctor() in ~\TestApp\TestApp\MainWindow.xaml.cs:line 28
InnerException: System.ArgumentException
HResult=-2147024809
Message='TestApp.Properties.Resources.Firstname' StaticExtension value cannot be resolved to an enumeration, static field, or static property.
Source=System.Xaml
StackTrace:
at System.Windows.Markup.StaticExtension.ProvideValue(IServiceProvider serviceProvider)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)
InnerException:
答案 0 :(得分:40)
您似乎需要使用PublicResXFileCodeGenerator
生成器。您是否尝试右键单击Visual Studio Solution Explorer中的资源文件并选择Properties
选项,然后将Custom Tool
属性设置为PublicResXFileCodeGenerator
?您还可以在Visual Studio的资源设计器窗口中将Access Modifier
属性设置为Public
。