日期:2014-05-17  浏览次数:20681 次

windows phone 自定义程序主题

开发windows Phone程序的时候,有时候会想要用具体某种的主题,比如说浅色主题,那么,如果一个拥有深色主题的手机安装了不就搞笑了,所以我

探索了下如果自定义程序的主题


第一步,C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Design 下面有相应的主题文件,主要有System.Windows.xaml和ThemeResources.xaml

把这两个文件拷贝到你的项目中去,比如说你要白色背景青绿色提醒色的话,就在lightlime下面拷贝这两个文件


第二步,在App.xaml的resources里面添加

<ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="System.Windows.xaml"/>
            </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>


第三步,在app.xaml.cs里面添加

InitializeComponent();

// 这一句为添加句
this.MergeCustomColors();


// Phone-specific initialization
InitializePhoneApplication();


以及添加相应方法

private void MergeCustomColors()
        {
            var dictionaries = new ResourceDictionary();
            string source = String.Format("/BingImageSearch;component/CustomTheme/ThemeResources.xaml");
            var themeStyles = new ResourceDictionary { Source = new Uri(source, UriKind.Relative) };
            dictionaries.MergedDictionaries.Add(themeStyles);




            ResourceDictionary appResources = App.Current.Resources;
            foreach (DictionaryEntry entry in dictionaries.MergedDictionaries[0])
            {
                SolidColorBrush colorBrush = entry.Value as SolidColorBrush;
                SolidColorBrush existingBrush = appResources[entry.Key] as SolidColorBrush;
                if (existingBrush != null && colorBrush != null)
                {
                    existingBrush.Color = colorBrush.Color;
                }
            }
        }


这样就可以定义了,还有更强的就是,你可以通过edit上面的两个文件,自己定义想要的效果