0

グローバルリソースディクショナリを使用しようとしていますが、それに含まれるスタイルを使用しようとするとエラーが発生します。私が持っている私app.xamlで:Windows Phone 7:グローバルリソースが見つかりません

<ListBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" x:Name="lstCategories" SelectionMode="Extended" Style="{StaticResource CategoryListTemplate}" ... 
:私はスタイルを設定しようとしている

<Style x:Key="CategoryListTemplate" TargetType="ListBox"> 
     <Setter Property="Background" Value="Transparent" /> 
     <Setter Property="SelectionMode" Value="Extended" /> 
     <Setter Property="BorderThickness" Value="0" /> 
     <Setter Property="ItemContainerStyle"> 
      <Setter.Value> 
       <Style TargetType="ListBoxItem"> 
        <Setter Property="Margin" Value="2" /> 
        <Setter Property="Template"> 
      .... 

:/Themes/ListBox.xamlで

<Application.Resources> 
     <ViewModel:ViewModelLocator x:Key="Locator" 
          d:IsDataSource="True" /> 
     <ResourceDictionary x:Key="dict1"> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="Themes/ListBox.xaml"/> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Application.Resources> 

ザ・、私はこれを持っています

Viwの読み込み中に「XamlParseException - Name/Key CategoryListTemplate [Line:30 Position:42]」というリソースが見つからない場合は、エラーが発生します。 42行目はリストボックス定義を含む行で、Style="{StaticResource CategoryListTemplate}"です。

LitBox.xamlのビルドアクションはResourceで設定されていますが、これは正しく動作するはずです。

答えて

0

私の代わりにApp.xaml.csに次のように使用して、これを解く:

var dictionaries = Resources.MergedDictionaries; 
      dictionaries.Clear(); 
      var dicts = new[]{ 
       "/ChickenPing.Mobile;component/Themes/ThemeResources.xaml", 
       "/ChickenPing.Mobile;component/Themes/generic.xaml", 
       "/ChickenPing.Mobile;component/Themes/ListBox.xaml", 
       "/ChickenPing.Mobile;component/Themes/Rating.xaml", 
       "/ChickenPing.Mobile;component/Themes/CheckBox.xaml", 
     }; 
      foreach (var dict in dicts) { 
       var themeStyles = new ResourceDictionary {Source = new Uri(dict, UriKind.Relative)}; 
       dictionaries.Add(themeStyles); 
      } 
関連する問題