Custom Theme That Overrides Default Theme WP7

后端 未结 3 547
执笔经年
执笔经年 2021-01-06 03:48

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

相关标签:
3条回答
  • 2021-01-06 04:23

    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.

    0 讨论(0)
  • 2021-01-06 04:29

    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:

    1. 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.

    2. 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!

    0 讨论(0)
  • 2021-01-06 04:37

    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.

    0 讨论(0)
提交回复
热议问题