本文整理汇总了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 });
//.........这里部分代码省略.........