Use a separate .xaml file to use resources in a WP8 application.

I want to use an external file to customize the styles in my application, but it does not work. I follow this step by step , but when I execute the project exception, it falls into:

In System.Windows.ni.dll

The first random error like "System.Windows.Markup.XamlParseException" occurred

My XAML code:

App.xaml:

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

Resources.xaml:

 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style TargetType="TextBox" x:Key="MyTextBox"> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderThickness" Value="0.5"/> <Setter Property="BorderBrush" Value="Gray"/> <Setter Property="Opacity" Value="0.5"/> <Setter Property="Foreground" Value="Red"/> </Style> </ResourceDictionary> 
+4
source share
1 answer

Try moving the local resource declarations inside the created ResourceDictionary and assign it to the Application.Resources property:

 <Application.Resources> <ResourceDictionary x:Key="myDict"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Resources.xaml"/> </ResourceDictionary.MergedDictionaries> <local:LocalizedStrings xmlns:local="clr-namespace:App1" x:Key="LocalizedStrings"/> <!-- other resources in here --> </ResourceDictionary> </Application.Resources> 
+5
source

All Articles