在家做网站怎么赚钱,广告联盟排行榜,湖北黄石域名注册网站建设,辽宁网站推广WP8中引用资源字典 当我们定义的样式太多的时候#xff0c;我们可以把样式分别定义在不同的文件中#xff0c;然后通过 MergedDictionaries 应用到其他资源字典中#xff0c;看下面Demo 我们可以把样式定义在多个文件中#xff0c;然后再App.xaml中引用 我们先定义三个文件…WP8中引用资源字典 当我们定义的样式太多的时候我们可以把样式分别定义在不同的文件中然后通过 MergedDictionaries 应用到其他资源字典中看下面Demo 我们可以把样式定义在多个文件中然后再App.xaml中引用 我们先定义三个文件 1、蓝色按钮资源文件定义按钮的Foreground为Blue ResourceDictionaryxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlStyle TargetTypeButtonSetter PropertyForeground ValueBlue/Setter/Style/ResourceDictionary BlueButtonResource.xaml 2、红色按钮资源文件定义按钮的Foreground为Red ResourceDictionaryxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlStyle TargetTypeButtonSetter PropertyForeground ValueRed/Setter/Style/ResourceDictionary RedButtonResource.xaml 3、全局资源文件在App.xaml引用这里只定义TextBlock为Teal ResourceDictionaryxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlStyle TargetTypeTextBlockSetter PropertyForeground ValueTeal/Setter/Style/ResourceDictionary GlobalResourceDictionary.xaml 然后再App.xaml全局引用全局资源文件 !--应用程序资源--Application.ResourcesResourceDictionaryResourceDictionary.MergedDictionaries!--这里引用其他文件当然也可以设置多个ResourceDictionary--ResourceDictionary SourceGlobalResourceDictionary.xaml//ResourceDictionary.MergedDictionaries!--这里定义其他样式--Style TargetTypeTextBlockSetter PropertyForeground ValueTeal/Setter/StyleStyle TargetTypeRectangleSetter PropertyFill Value{StaticResource PhoneAccentBrush}/Setter/Style/ResourceDictionary/Application.Resources 前面蓝色和红色按钮的两个资源文件可以用来当成不同的主题我们可以在代码中动态加载 ResourceDictionary resourceDictionary new ResourceDictionary();//这里的Uri格式/解决方案;component/资源文件路径Application.LoadComponent(resourceDictionary, new Uri(/LoadResourceDictionary;component/BlueButtonResource.xaml, UriKind.Relative));Application.Current.Resources.MergedDictionaries.Add(resourceDictionary); 转载于:https://www.cnblogs.com/bomo/p/3618522.html