【问题标题】:The attachable property "ThemeDictionaries" was not found in type "ResourceDictionary"在“ResourceDictionary”类型中找不到可附加属性“ThemeDictionaries”
【发布时间】:2015-05-24 06:10:06
【问题描述】:

以下代码位于 Windows Phone 8 应用程序的 app.xaml 中。它收到错误The attachable property "ThemeDictionaries" was not found in type "ResourceDictionary"。同样,它不设置背景。我正在尝试通过 c# 代码使用(App.Current.Resources["BackgroundImage"] as ImageBrush).ImageSource = imgSrc; 更改它的选项来设置整个应用程序的背景。

<Application
    x:Class="MyApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">  
     <Application.Resources>
          <ResourceDictionary>
           <ResourceDictionary.ThemeDictionaries>
              <ResourceDictionary x:Key="Default">
                    <ImageBrush x:Key="BackgroundImage" ImageSource="Assets/BackgroundDefault.jpg" Stretch="UniformToFill" />
              </ResourceDictionary>
              <ResourceDictionary x:Key="Dark">
                    <ImageBrush x:Key="BackgroundImage" ImageSource="Assets/BackgroundDark.jpg" Stretch="UniformToFill" />
              </ResourceDictionary>
           </ResourceDictionary.ThemeDictionaries>
            <local:LocalizedStrings xmlns:local="clr-namespace:MyApp" x:Key="LocalizedStrings"/>
            <DataTemplate x:Key="SmallPanoramaTitle">
                <ContentPresenter>
                    <TextBlock Text="{Binding}" FontSize="25" Margin="0,30,0,0" />
                </ContentPresenter>
            </DataTemplate>
        </ResourceDictionary>
      </Application.Resources>
      <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService
            Launching="Application_Launching" Closing="Application_Closing"
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>
       </Application.ApplicationLifetimeObjects>
</Application>

【问题讨论】:

    标签: c# xaml windows-phone-8 resourcedictionary app.xaml


    【解决方案1】:

    ResourceDictionary.ThemeDictionaries 在 windows phone silverlight 应用程序中不可用。

    您可以使用ThemeManager 库在 WP silverlight 中管理您的主题。这是一个很棒的图书馆,它也可以在nuget 找到。

    查看this 页面了解如何使用 ThemeManager 。您还可以加载自定义主题文件

    【讨论】:

    • 谢谢,不过 ThemeManager 似乎坏了。在新的全景页面上调用时,只需使用 ThemeManager.SetBackground(new Uri("Assets/backgroundImage.jpg", UriKind.Relative)); 不会产生任何效果。
    • 确保您没有在每个页面中设置背景颜色
    猜你喜欢
    • 1970-01-01
    • 2013-01-12
    • 2015-11-23
    • 1970-01-01
    • 2020-11-08
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多