Reputation: 165
I'm making an app for windows phone 7 (using Visual Studio 2010 Express for Windows Phone RTM), and i'm having some problems regarding theme (light/dark) awareness especially with colors.
Basically i want to do the same thing that the phone does internally when using the staticresource colors/brushes. For example, if i declare:
<Border Background="{StaticResource PhoneBackgroundBrush}" />
The Border will have a black background with the Dark Theme and White with the Light one. So, i want to have a resource ... let's say MyBackgroundBrush, and will be used like:
<Border Background="{StaticResource MyBackgroundBrush}" />
And, it will have, maybe blue for the Dark theme, and red for the light.
So my question is, how can i define such resource and behavior?
Upvotes: 1
Views: 1187
Reputation: 25146
See this question about theme detection. That would get you a way to detect the theme, then use that information to set your background brush by replacing it in the app's resources:
App.Current.Resources.Remove("MyPhoneBrush");
App.Current.Resources.Add("MyPhoneBrush", value);
You could define both of the colored brushes with a name in xaml, then set one or the other as the runtime value of MyPhoneBrush. you'd probably want to set one of them as the default so things work at design time too...
Upvotes: 1