How to concatenate LocalizedStrings and ResourceDictionary labels in Application.Resources of App.xaml file

I would like to use the style file as well as the LocalizedStrings file as resources in a Windows Phone 8 application using 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 declare LocalizedStrings as a resource that we can use:

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

      

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

Visual Studio prevents me from adding the LocalizedStrings tag above the ResourceDictionary tag by asking for a key, and VS also prevents me from adding the LocalizedString tag inside the ResourceDictionnary tag. But VS is calm 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 starting the application I got XamlParseException

with additional information: Failed to assign property System.Windows.ResourceDictionnary.Source

.

So, do you know how to combine these two resources in the App.xaml file?

+3


source to share


2 answers


You can add both codes below.

<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 use both in my application and there won't be any exceptions.

+2


source


I followed Kunjan Patel's idea but still didn't work. So I tried "LocalizedStrings" before "ResourceDictionary.MergedDictionaries" and it worked! See below.

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

      



0


source







All Articles