在结合资源字符串错误与WPF中的视图视图、字符串、错误、资源

2023-09-04 00:24:56 作者:Story!劇終°

我想绑定在Resources.resx称为标题中定义一个静态的字符串,当我运行下面的下面的错误应用。一旦在这个论坛调查的错误,我发现生成的资源类被标记为内部和WPF试图解析从另一个程序集资源,以便它不会成功,直到你的资源被标记为公开。同样我有一个包含我的观点和资源单个项目定义我不需要任何朋友集会,我相信内部类可以在同一个组件内进行访问。我发现了一个类似的帖子由家伙点击这里他在其中建议使用ResXFile codeGenerator。请有你说这个

 发生System.Windows.Markup.XamlParseException
HResult的= -2146233087
消息= System.Windows.Markup.StaticExtension'上提供价值''引发了异常。行号'11'和线位9。
来源= presentationFramework
行号= 11
LinePosition = 9
堆栈跟踪:
   在System.Windows.Markup.WpfXamlLoader.Load(的XamlReader的XamlReader,IXamlObjectWriterFactory writerFactory,布尔skipJournaledProperties,对象rootObject,XamlObjectWriterSettings设置,开放的基本URI)
   在System.Windows.Markup.WpfXamlLoader.LoadBaml(的XamlReader的XamlReader,布尔skipJournaledProperties,对象rootObject,XamlAccessLevel ACCESSLEVEL,乌里基本URI)
   在System.Windows.Markup.XamlReader.LoadBaml(流流,ParserContext parserContext,对象父,布尔closeStream)
   在System.Windows.Application.LoadComponent(对象组件,乌里resourceLocator)
   在TestApp.MainWindow.InitializeComponent()在〜\ TestApp \ TestApp \ MainWindow.xaml:1号线
   在TestApp.MainWindow..ctor()在〜\ TestApp \ TestApp \ MainWindow.xaml.cs:行28
的InnerException信息:System.ArgumentException
   HResult的= -2147024809
   消息='TestApp.Properties.Resources.Firstname'StaticExtension价值不能被解析为枚举,静态字段或静态属性。
   来源= System.Xaml
   堆栈跟踪:
        在System.Windows.Markup.StaticExtension.ProvideValue(的IServiceProvider的ServiceProvider)
        在MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(的MarkupExtension我的IServiceProvider的ServiceProvider)
   的InnerException:
 

解决方案

看来你需要使用 PublicResXFile codeGenerator 发电机。您是否尝试过右键单击在Visual Studio解决方案资源管理器的资源文件,并选择属性选项,然后设置自定义工具属性 PublicResXFile codeGenerator ?您还可以设置访问修饰符属性公开在Visual Studio中的资源设计器窗口。

I am trying to bind a static string defined in the Resources.resx called title, When i run the application i get the following error below. Upon investigating the error in this forum i found that generated Resources class is marked internal and WPF is trying to resolve resource from another assembly so it wont succeed until your resources are marked as public. Same I have a single project which contains my views and resources defined i dont need any friend assembly, i believe internal class can be accessed within the same assembly. I found a similar post by a fellow Click here in which he suggested to use ResXFileCodeGenerator. Please have your say on this

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: 
wpf之MVVM

解决方案

It seems that you need to use the PublicResXFileCodeGenerator generator. Have you tried right clicking on the resource file in the Visual Studio Solution Explorer and selecting the Properties option and then setting the Custom Tool property to PublicResXFileCodeGenerator? You can also set the Access Modifier property to Public in the resources designer window in Visual Studio.