Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Combine LocalizedStrings and ResourceDictionary tags in the Application.Resources of the App.xaml file

I would like to use a Style file as well as a LocalizedStrings file as resources, in a Windows Phone 8 application, using the App.xaml.

I know that to add a style file as a resource we can use:

<Application.Resources> 
    <ResourceDictionary> 
        <ResourceDictionary.MergedDictionaries> 
            <ResourceDictionary Source="Assets/Resources/Styles.xaml" /> 
        </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources>

and to declare a LocalizedStrings as a resource we can use:

<Application.Resources> 
    <local:LocalizedStrings xmlns:local="clr-namespace:Localizzazione" x:Key="LocalizedStrings"/> 
</Application.Resources>

Both work well in my app individually. But I have some issues when trying to use both resources at the same time.

Visual Studio prevent me to add the LocalizedStrings tag above the ResourceDictionary tag, asking me for a key, and VS also prevent me to add the LocalizedString tag inside the ResourceDictionnary tag. But VS is quiet when I do the following:

<Application.Resources> 
    <local:LocalizedStrings xmlns:local="clr-namespace:Localizzazione" x:Key="LocalizedStrings"/> 
    <ResourceDictionary x:Key="MyAppDict"> 
        <ResourceDictionary.MergedDictionaries> 
            <ResourceDictionary Source="Assets/Resources/Styles.xaml" /> 
        </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources>

But when running the app I got an XamlParseException with Additional Info: Failed to assign to property System.Windows.ResourceDictionnary.Source.

So do you have any idea on how to combine those two resources in the App.xaml file?

like image 704
godidier Avatar asked Oct 15 '25 15:10

godidier


1 Answers

You can add both using below code.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="./Resources/ThemeResources.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <local:LocalizedStrings xmlns:local="clr-namespace:Localizzazione" x:Key="LocalizedStrings"/>            
    </ResourceDictionary>
</Application.Resources>

I am using both in my application & it will not showing any exception there.

like image 89
Kunjan Patel Avatar answered Oct 18 '25 08:10

Kunjan Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!