How to use local resources in shared classes?

I have a parent project and a child project. In the child project, I deleted all the classes (MainPage.xaml and its .cs file) and linked the Parent Project MainPage.xaml and its .cs file using Add as a link.

In my child project Project, I want to start a project using these project resource files (e.g. AppResources.resx). For example, I want to print a customized string value from AppResources.resx from a 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 code above prints the child name of the project.

I would like to achieve this by entering the code in my .cs file. Using the operator below, I can do this,

 Txtblk.Text = AppResources.ApplicationTitle; 

But for this I need to add the resources of the parent projects and return the values โ€‹โ€‹of the resource of the parent project ...

I want to use the 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 do this job?

Thanks.

0
source share
1 answer

The solution is to have 2 resource files for each project. One that is common / related in all projects and then unique to each project. Give then different names, and then you can refer to the specific one you want in every place.

0
source

All Articles