可附加物业" ThemeDictionaries"在类型" ResourceDictionary"中找不到

时间:2015-05-24 06:10:06

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

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

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

1 个答案:

答案 0 :(得分:1)

ResourceDictionary.ThemeDictionaries在Windows Phone Silverlight应用程序中不可用。

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

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