当前位置: 首页>>代码示例>>C#>>正文


C# SolidColorBrush.GetAsFrozen方法代码示例

本文整理汇总了C#中System.Windows.Media.SolidColorBrush.GetAsFrozen方法的典型用法代码示例。如果您正苦于以下问题:C# SolidColorBrush.GetAsFrozen方法的具体用法?C# SolidColorBrush.GetAsFrozen怎么用?C# SolidColorBrush.GetAsFrozen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.SolidColorBrush的用法示例。


在下文中一共展示了SolidColorBrush.GetAsFrozen方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyThemeInternal

        private static void ApplyThemeInternal(this FrameworkElement control, Theme? theme, SolidColorBrush accentBrush, SolidColorBrush contrastBrush)
        {
            ValidationHelper.NotNull(control, () => control);

            // Resource dictionaries paths
            var lightBrushesUri = new Uri("/Elysium;component/Themes/LightBrushes.xaml", UriKind.Relative);
            var darkBrushesUri = new Uri("/Elysium;component/Themes/DarkBrushes.xaml", UriKind.Relative);

            // Resource dictionaries
            var lightBrushesDictionary = new ResourceDictionary { Source = lightBrushesUri };
            var darkBrushesDictionary = new ResourceDictionary { Source = darkBrushesUri };

            if (theme == Theme.Light)
            {
                // Add LightBrushes.xaml, if not included
                if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != lightBrushesUri))
                {
                    control.Resources.MergedDictionaries.Add(lightBrushesDictionary);
                }

                // Remove DarkBrushes.xaml, if included
                var darkColorsDictionaries = control.Resources.MergedDictionaries.Where(dictionary => dictionary.Source == darkBrushesUri).ToList();
                foreach (var dictionary in darkColorsDictionaries)
                {
                    control.Resources.MergedDictionaries.Remove(dictionary);
                }
            }
            if (theme == Theme.Dark)
            {
                // Add DarkBrushes.xaml, if not included
                if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != darkBrushesUri))
                {
                    control.Resources.MergedDictionaries.Add(darkBrushesDictionary);
                }

                // Remove LightBrushes.xaml, if included
                var lightColorsDictionaries = control.Resources.MergedDictionaries.Where(dictionary => dictionary.Source == lightBrushesUri).ToList();
                foreach (var dictionary in lightColorsDictionaries)
                {
                    control.Resources.MergedDictionaries.Remove(dictionary);
                }
            }

            // Bug in WPF 4: http://connect.microsoft.com/VisualStudio/feedback/details/555322/global-wpf-styles-are-not-shown-when-using-2-levels-of-references
            if (control.Resources.Keys.Count == 0)
            {
                control.Resources.Add(typeof(Window), new Style(typeof(Window)));
            }

            if (accentBrush != null)
            {
                var accentBrushFrozen = !accentBrush.IsFrozen && accentBrush.CanFreeze ? accentBrush.GetAsFrozen() : accentBrush;
                if (control.Resources.Contains("AccentBrush"))
                {
                    // Set AccentBrush value, if key exist
                    control.Resources["AccentBrush"] = accentBrushFrozen;
                }
                else
                {
                    // Add AccentBrush key and value, if key doesn't exist
                    control.Resources.Add("AccentBrush", accentBrushFrozen);
                }
            }

            if (contrastBrush != null)
            {
                var contrastBrushFrozen = !contrastBrush.IsFrozen && contrastBrush.CanFreeze ? contrastBrush.GetAsFrozen() : contrastBrush;
                if (control.Resources.Contains("ContrastBrush"))
                {
                    // Set ContrastBrush value, if key exist
                    control.Resources["ContrastBrush"] = contrastBrushFrozen;
                }
                else
                {
                    // Add ContrastBrush key and value, if key doesn't exist
                    control.Resources.Add("ContrastBrush", contrastBrushFrozen);
                }

                var semitransparentContrastBrush = contrastBrush.Clone();
                semitransparentContrastBrush.Opacity = 1d / 8d;
                var semitransparentContrastBrushFrozen = !semitransparentContrastBrush.IsFrozen && semitransparentContrastBrush.CanFreeze
                                                             ? semitransparentContrastBrush.GetAsFrozen()
                                                             : semitransparentContrastBrush;
                if (control.Resources.Contains("SemitransparentContrastBrush"))
                {
                    // Set SemitransparentContrastBrush value, if key exist
                    control.Resources["SemitransparentContrastBrush"] = semitransparentContrastBrushFrozen;
                }
                else
                {
                    // Add SemitransparentContrastBrush key and value, if key doesn't exist
                    control.Resources.Add("SemitransparentContrastBrush", semitransparentContrastBrushFrozen);
                }
            }

            // Add Generic.xaml, if not included
            var genericDictionaryUri = new Uri("/Elysium;component/Themes/Generic.xaml", UriKind.Relative);
            if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != genericDictionaryUri))
            {
                control.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = genericDictionaryUri });
//.........这里部分代码省略.........
开发者ID:oysteinkrog,项目名称:MonitorControl,代码行数:101,代码来源:ThemeManager.cs


注:本文中的System.Windows.Media.SolidColorBrush.GetAsFrozen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。