2013-02-12 70 views
4

我想使用外部文件來定製我的應用程序的樣式,但它不起作用。我下面這個step-by-step但是當我執行的項目除外分爲:類型System.Windows.Markup.XamlParseException「的使用單獨的.xaml文件來使用WP8應用程序中的資源

第一次機會異常出現在System.Windows.ni.dll

我的XAML代碼:

的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> 

Resou rces.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> 

回答

5

嘗試移動,你創建並分配到Application.Resources財產ResourceDictionary內本地資源聲明:

<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> 
+2

謝謝您全面的答案,但這樣一來,標籤ResourceDictionary不可接受使用屬性x:Key。刪除此屬性一切工作正常。 此致敬禮! – CodeSculptor 2013-02-12 03:06:52

相關問題