In shared classes how to use local resources?

我怕爱的太早我们不能终老 提交于 2019-12-25 06:59:53

问题


I have a Parent project and a child project. In the child project I have removed all the classes (MainPage.xaml and it's .cs file) and have linked the Parent Project's MainPage.xaml and it's .cs file using Add as a link.

In my child Project I want to run the project using this project's resource files(like AppResources.resx). For example, I want to print a customised string value from AppResources.resx from child project, I use this code in my xaml..

<TextBlock x:Name="Txtblk" HorizontalAlignment="Left" Margin="56,147,0,0" Grid.Row="1" TextWrapping="Wrap" 
                  Text="{Binding Path=LocalizedResources.ApplicationName, Source={StaticResource LocalizedStrings}}"  
                   VerticalAlignment="Top" Height="87" Width="155"/>

The above code prints child Project's name.

I would like to achieve this bringing the code into my .cs file. Using the below statement I can do that ,

Txtblk.Text = AppResources.ApplicationTitle;

But to do this, I have to add Parent Projects resources and it returns Parent Project's resource values...

I want to use binding principle like

Binding b = new Binding();
b.Source = LocalizedStrings; // How do I set this to {StaticResource LocalizedStrings}
b.Path = new PropertyPath("LocalizedResources.ApplicationName");
b.Mode = BindingMode.OneWay;
Txtblk.SetBinding(TextBlock.TextProperty, b);

How do I make this work?

Thanks.


回答1:


The solution is to have 2 resource files for each project. One that is shared/linked across all projects and then one that is unique to each project. Give then different names and then you can refer to the specific one you want in each location.



来源:https://stackoverflow.com/questions/21258300/in-shared-classes-how-to-use-local-resources

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