當用戶在其設置中更改手機主題時,我試圖更改ImageBrush的ImageSource。主題變更時更改背景圖片
所以目前我有這樣的:
XAML:
<ImageBrush ImageSource="{Binding ImageSource, Mode=OneTime}" Stretch="UniformToFill"/>
代碼隱藏:
public string ImageSource
{
get
{
if ((Visibility)App.Current.Resources["PhoneDarkThemeVisibility"]
== Visibility.Visible)
{
return "/Images/BGDark.png";
}
else
{
return "/Images/BG.png";
}
}
private set { }
}
正如你所看到的,我設置背景當應用程序已經啓動。該應用程序將通過查看選擇哪個主題來設置背景。
我現在的問題是,當用戶轉到設置(應用程序尚未關閉!)並更改主題時,Background/ImageSource將不會更新,當他激活應用程序時。 我想,也許我可以在這裏設置新的背景變化吧:
App.xaml.cs:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
//access somehow the CodeBehind of my MainPage and change the ImageSource
}
但我不知道我怎麼會訪問屬性... 當應用程序仍在運行並且用戶更改主題時,是否有另一種更改背景的解決方案?
工作正常,謝謝:) – Rudi 2014-09-02 12:22:32