Created
January 5, 2013 17:34
-
-
Save jasonmitchell/4462646 to your computer and use it in GitHub Desktop.
Associated blog post: http://jason-mitchell.com/windows-phone/theme-aware-panorama-control-for-windows-phone/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<local:ThemeAwarePanorama Title="my app" | |
LightBackground="/MyApp;component/Content/Images/Light/Background.jpg" | |
DarkBackground="/MyApp;component/Content/Images/Dark/Background.jpg"> | |
<!-- more xaml --> | |
</local:ThemeAwarePanorama> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThemeAwarePanorama : Panorama | |
{ | |
public static readonly DependencyProperty LightBackgroundProperty = DependencyProperty.Register("LightBackground", typeof (string), typeof (ThemeAwarePanorama), new PropertyMetadata(default(string))); | |
public static readonly DependencyProperty DarkBackgroundProperty = DependencyProperty.Register("DarkBackground", typeof (string), typeof (ThemeAwarePanorama), new PropertyMetadata(default(string))); | |
public ThemeAwarePanorama() | |
{ | |
Loaded += (sender, args) => | |
{ | |
if (!string.IsNullOrEmpty(LightBackground) && !string.IsNullOrEmpty(DarkBackground)) | |
{ | |
string url = UIHelper.IsLightThemeEnabled() ? LightBackground : DarkBackground; | |
Background = new ImageBrush {ImageSource = new BitmapImage(new Uri(url, UriKind.Relative))}; | |
} | |
else | |
{ | |
throw new InvalidOperationException("Light and dark background must be provided"); | |
} | |
}; | |
} | |
public string LightBackground | |
{ | |
get { return (string) GetValue(LightBackgroundProperty); } | |
set { SetValue(LightBackgroundProperty, value); } | |
} | |
public string DarkBackground | |
{ | |
get { return (string)GetValue(DarkBackgroundProperty); } | |
set { SetValue(DarkBackgroundProperty, value); } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class UIHelper | |
{ | |
public static bool IsLightThemeEnabled() | |
{ | |
return (Visibility) Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment