My.Resources in WPF XAML?

前端 未结 2 1598
时光说笑
时光说笑 2021-01-18 04:29

Is there a way to access My.Resources thru Xaml?

Like this



        
2条回答
  •  醉话见心
    2021-01-18 05:24

    The problem is that by default, the tool that generates code for the Resources.resx file is VbMyResourcesResXFileCodeGenerator ("Custom tool" property of the project item). This tool generates a Module in which the resource properties are internal (Friend), so the StaticExtension can't access it. To solve that problem, you should change the custom tool for Resources.resx to PublicVbMyResourcesResXFileCodeGenerator, which will generate public members.

    Also, a VB module is roughly equivalent to a static (Shared) class, so there is no instance of Resources that could be used as the source of the binding, so you can't specify a Path for the binding. You should set the binding source directly to the property you want :

    
    

    Note: there is another pair of tools available to generate the code for a resource file : ResXFileCodeGenerator and PublicResXFileCodeGenerator. These tools generate a class instead of a module.

    EDIT: The namespace mapping to use is the following :

    xmlns:myRes="clr-namespace:YourApplicationName.My.Resources"
    

提交回复
热议问题