2016-10-18 9 views
0

Windows Phone 8(Silverlight)プロジェクトを新しく作成しました。 追加テーマフォルダは、このフォルダにsolidcolorburshを含むものを含むものを2つのリソースの辞書を追加しました。Windows Phone 8プロジェクトの名前/キーでリソースを見つけることができません

私は、グリッドの背景に1 solidcolorburshを使用MainPage.xamlをでApp.xaml

におけるこれら2つのリソース辞書をマージ。

コードスニペット:

App.xaml:

<Application.Resources> 
     <ResourceDictionary x:Key="mainStyle"> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="/resTest;component/Themes/MyColors.xaml"></ResourceDictionary>  
       <ResourceDictionary Source="/resTest;component/Themes/MyStyles.xaml"></ResourceDictionary> 
      </ResourceDictionary.MergedDictionaries> 
      <local:LocalizedStrings xmlns:local="clr-namespace:resTest" x:Key="LocalizedStrings"/>  
     </ResourceDictionary>   
    </Application.Resources> 

MainPage.xamlを:

<Grid x:Name="LayoutRoot" Background="{StaticResource RedSolidColorBrush}"> 
</Grid> 

MyColors.xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="d"> 

    <Color x:Key="RedColor">#FFFF0000</Color> 
</ResourceDictionary> 

MyStyles.xaml:スロー

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        mc:Ignorable="d"> 

    <SolidColorBrush x:Key="RedSolidColorBrush" Color="{StaticResource RedColor}"></SolidColorBrush> 
</ResourceDictionary> 

が例外:私は間違っ

Blockquote

'System.Windows.Markup.XamlParseException' in System.Windows.ni.dll Its showing runtime error:

Exception thrown: 'System.Windows.Markup.XamlParseException' in System.Windows.ni.dll

Additional information: Cannot find a Resource with the Name/Key RedColor [Line: 14 Position: 44]

参考https://msdn.microsoft.com/en-us/library/cc903952(VS.95).aspx

https://joshsmithonwpf.wordpress.com/2010/09/24/consuming-resources-from-external-assemblies-in-silverlight-4/

Referencing a merged resource dictionary in windows phone seven failing

答えて

0

あなたはMyStyles.xamlからMyColors.xamlを見ることができるようにする必要があり、それ以外の場合は見つけることができません0123の定義。

あなたはMyStyles.xamlに次のものが含まれている場合:「...」MyColors.xamlへのパスです

<ResourceDictionary.MergedDictionaries> 
    <ResourceDictionary Source="...";component/MyColors.xaml" /> 
</ResourceDictionary.MergedDictionaries> 

は、あなたは、その中に定義された色を参照することができるはずです。

すでに完了しているので、App.xamlに辞書をマージしても同じ効果が得られます。 MyStyles.xamlMyColors.xamlを含めるように変更する場合は、MyColors.xamlへの参照をApp.xamlから削除する必要があります。

0

まず第一に: のResourceDictionaryファイルのビルドアクションがリソースに設定されている場合は、この方法でそれを参照することができます

/<assembly name>;component/<resource file path> 

ビルドアクションがコンテンツに設定されている場合、あなたはそれを参照することができますこの方法:次に

/<resource file path> 

: 我々はMyStylesでMyColorsをマージする必要があります。 ありがとうございました@ChrisF

実際に私はこれらの問題がないWindows Phone 8.1またはUWPのコードに使用されています。

関連する問題