[英]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. 我想使用App.xaml在Windows Phone 8应用程序中使用Style文件和LocalizedStrings文件作为资源。
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: 并声明LocalizedStrings作为我们可以使用的资源:
<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. Visual Studio阻止我在ResourceDictionary标记上方添加LocalizedStrings标记,向我询问密钥,VS也阻止我在ResourceDictionnary标记内添加LocalizedString标记。 But VS is quiet when I do the following: 但是当我执行以下操作时VS很安静:
<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
. 但是当运行应用程序时,我得到了一个带有附加信息的XamlParseException
:无法分配给属性System.Windows.ResourceDictionnary.Source
。
So do you have any idea on how to combine those two resources in the App.xaml file? 那么你对如何在App.xaml文件中组合这两个资源有任何想法吗?
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. 我在我的应用程序中使用它们并且它不会在那里显示任何异常。
I followed Kunjan Patel's idea but still didn't work. 我遵循了Kunjan Patel的想法,但仍然没有奏效。 So I tried "LocalizedStrings" before the "ResourceDictionary.MergedDictionaries" and it worked! 所以我在“ResourceDictionary.MergedDictionaries”之前尝试了“LocalizedStrings”并且它有效! 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.