2015-05-24 87 views
0

以下代碼位於Windows Phone 8應用程序的app.xaml內。它收到錯誤The attachable property "ThemeDictionaries" was not found in type "ResourceDictionary"。同樣,它不設置背景。我正在嘗試在整個應用程序中設置背景,並使用(App.Current.Resources["BackgroundImage"] as ImageBrush).ImageSource = imgSrc;通過c#代碼進行更改。在「ResourceDictionary」類型中未找到可附加屬性「ThemeDictionaries」

<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

ResourceDictionary.ThemeDictionaries不適用於windows phone silverlight應用程序。

您可以使用ThemeManager庫來管理WP silverlight中的主題。這是一個優秀的圖書館,並且其在nuget也可用。

查看this頁面瞭解如何使用ThemeManager。你也可以加載自定義主題文件

+0

謝謝,ThemeManager似乎破了。只需使用'ThemeManager.SetBackground(new Uri(「Assets/backgroundImage.jpg」,UriKind.Relative));'在新的全景頁面上調用時不執行任何操作並且不起作用。 – Euthyphro

+0

確保您沒有在每個頁面中設置背景顏色 –

相關問題