Is it possible to create a custom theme and have it used as the default theme?
Every example I can find anywhere says you can create custom themes by copying the ThemeResources.xaml
and System.Windows.xaml
files and including them as merged dictionaries in your app.
http://windowsphonegeek.com/articles/Creating-WP7-Custom-Theme-ndash-Basic-Theme-Implementation
Overriding themes in Windows Phone 7
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/CustomThemeResources.xaml" />
<ResourceDictionary Source="Resources/CustomThemeStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Then I've read some more that you need to include the brushes inside the styles file, so in CustomThemeStyles.xaml
I have this.
http://www.windowsphonegeek.com/articles/Creating-WP7-Custom-Theme---Complex-Theme
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CustomThemeResources.xaml" />
</ResourceDictionary.MergedDictionaries>
It doesn't work... so I download the sample app and sure enough, every page that wants to have some color changed, like the background color, will set it on it's outer most component.
<Grid Background="{StaticResource PhoneBackgroundBrush}">
...
</Grid>
Is it possible to include custom themes that change the style/brushes/colors/etc of all the defaults without having to explicitly set them everywhere?
It is not possible in the current version of WP7 to have a new Style that changes the default one without explicitly set it via "x:Key":
Implicit Styles are a feature of Silverlight 4 (and WPF): Windows Phone 7 is based on Silverlight 3+(with a few Silverlight 4 features added). Since there’s no Implicit Styles in Silverlight 3 this mean that there is no way to use them in Windows Phone 7 as well.
For now you can:
Only override the default Brushes/Colors resources as explained in the first article that you pointed out. Note that all WP7 controls will change their colors. Note also that for some reason the default Background remains unchanged. This is a known issue with the current version of WP7 and probably will be fixed in the "Mango" update.
If you want to have any new Style/ControlTemplate you must use the "x:Key"/{StaticResource ...} approach as mentioned in the second article that you pointed out.
Finally, as Derek Lakin mentioned previously: hopefully this bug will get fixed in the Mango update!
If you create a resource dictionary and call it something like Reset.xaml that contains all of the standard brush resources. Put any custom resource styles/brushes into another resource dictionary (we'll call it Custom.xaml for now). In App.xaml include both of these resource dictionaries as shown here:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Reset.xaml"/>
<ResourceDictionary Source="Resources/Custom.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
In theory, this should be enough, but unfortunately it's not. For some reason (hopefully a bug that will get fixed in the Mango update) you also need to include the Reset.xaml in the Custom.xaml like this:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Reset.xaml"/>
</ResourceDictionary.MergedDictionaries>
Once you've done this, that should be it; you shouldn't need to do anything else.
With the release of Windows Phone Mango (7.1), the feature of merging XAML dictionary styles no longer works. Currently, you will have to change the application resource Brush color entry in the code-behind; preferably in constructor of App() in App.xaml.cs.
Example:
(App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Color.FromArgb(12, 12, 54, 145);
(App.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush).Color = Colors.Green;
(App.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush).Color = Colors.Purple;
Hopefully in the WP8 SDK we will no longer need to do this workaround.