Can't find “Resources” file in wpf

我只是一个虾纸丫 提交于 2019-12-23 19:02:00

问题


I'm newbe in WPF. I need to add reference on the resources file resx and get strings from it.

<Window x:Class="SelectObjectsWindow.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:res="clr-namespace:SelectObjectsWindow.Properties"

    Title="{x:Static res:Resources.Res1}" Height="350" Width="525">
<Grid>
    ....
</Grid>

I got an error: The name "Resources" does not exist in the namespace "clr-namespace:SelectObjectsWindow.Properties". I was searching information about this and find couple of advises: Set "public" access modifier of resx file. Change Build Action property of resx on "Embedded Resource".

So, I did it, but nothing changed. I checked all namespaces. Seems to be ok. I don't know, what else I should try.

In .cs i can do this without error

  var res = Properties.Resources.Res1;

Do somebody know, what is wrong?


回答1:


Change access modifier from internal to public, your binding will work.




回答2:


Try adding an Assembly reference:

xmlns:res="clr-namespace:SelectObjectsWindow.Properties;assembly=[AssemblyName]"

Replace [AssemblyName] with the name of your assembly which can be found by right clicking your project and selecting Properties, go to the Application tab and see Assembly name:



来源:https://stackoverflow.com/questions/33611419/cant-find-resources-file-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!