public void TestIsRuntimeGeneratedThemeDictionary() { Assert.That(LibraryTheme.IsRuntimeGeneratedThemeDictionary(new ResourceDictionary()), Is.False); Assert.That(LibraryTheme.IsRuntimeGeneratedThemeDictionary(GenerateValidResourceDictionary()), Is.False); Assert.That(LibraryTheme.IsRuntimeGeneratedThemeDictionary(GenerateValidRuntimeGeneratedResourceDictionary()), Is.True); }
public void TestPropertiesFromResourceDictionary() { var resourceDictionary = new ResourceDictionary { { Theme.ThemeNameKey, "Generated" }, { Theme.ThemeColorSchemeKey, "Red" }, { Theme.ThemeDisplayNameKey, "Generated DisplayName" }, { Theme.ThemePrimaryAccentColorKey, Colors.Red }, { Theme.ThemeBaseColorSchemeKey, "Custom" }, { Theme.ThemeOriginKey, "UnitTest" }, { Theme.ThemeIsHighContrastKey, true }, { Theme.ThemeShowcaseBrushKey, Brushes.Pink }, { Theme.ThemeIsRuntimeGeneratedKey, true }, { LibraryTheme.LibraryThemeAlternativeColorSchemeKey, "Alternative" } }; var theme = new LibraryTheme(resourceDictionary, null); Assert.That(theme.IsHighContrast, Is.True); Assert.That(theme.PrimaryAccentColor, Is.EqualTo(Colors.Red)); Assert.That(theme.AlternativeColorScheme, Is.EqualTo("Alternative")); Assert.That(theme.ColorScheme, Is.EqualTo("Red")); Assert.That(theme.IsRuntimeGenerated, Is.True); Assert.That(theme.BaseColorScheme, Is.EqualTo("Custom")); Assert.That(theme.DisplayName, Is.EqualTo("Generated DisplayName")); Assert.That(theme.Name, Is.EqualTo("Generated")); Assert.That(theme.LibraryThemeProvider, Is.Null); Assert.That(theme.Origin, Is.EqualTo("UnitTest")); Assert.That(theme.ParentTheme, Is.Null); Assert.That(theme.ShowcaseBrush, Is.EqualTo(Brushes.Pink)); Assert.That(theme.Resources, Is.Not.Null); Assert.That(theme.Resources[LibraryTheme.LibraryThemeInstanceKey], Is.EqualTo(theme)); Assert.That(theme.ToString(), Is.EqualTo("DisplayName=Generated DisplayName, Name=Generated, Origin=UnitTest, IsHighContrast=True")); }
public ThemeResource(Theme theme, LibraryTheme libraryTheme, ResourceDictionary resourceDictionary, string key, object value) { this.Theme = theme; this.LibraryTheme = libraryTheme; this.Source = resourceDictionary.Source?.ToString() ?? "Runtime"; this.Key = key; this.Value = value switch { Color color => new Rectangle { Fill = new SolidColorBrush(color) }, Brush brush => new Rectangle { Fill = brush }, _ => null }; this.StringValue = value.ToString(); }
public void TestFromUri() { var source = new Uri("pack://application:,,,/ControlzEx.Tests;component/Themes/Themes/Dark.Red.xaml"); var theme = new LibraryTheme(source, null); Assert.That(theme.IsHighContrast, Is.False); Assert.That(theme.PrimaryAccentColor, Is.EqualTo(ColorConverter.ConvertFromString("#FFE51400"))); Assert.That(theme.AlternativeColorScheme, Is.Null); Assert.That(theme.ColorScheme, Is.EqualTo("Red")); Assert.That(theme.IsRuntimeGenerated, Is.False); Assert.That(theme.BaseColorScheme, Is.EqualTo("Dark")); Assert.That(theme.DisplayName, Is.EqualTo("Red (Dark)")); Assert.That(theme.Name, Is.EqualTo("Dark.Red")); Assert.That(theme.LibraryThemeProvider, Is.Null); Assert.That(theme.Origin, Is.EqualTo("ControlzEx.Showcase")); Assert.That(theme.ParentTheme, Is.Null); Assert.That(theme.ShowcaseBrush.ToString(), Is.EqualTo("#FFE51400")); Assert.That(theme.Resources, Is.Not.Null); Assert.That(theme.Resources[LibraryTheme.LibraryThemeInstanceKey], Is.EqualTo(theme)); Assert.That(theme.ToString(), Is.EqualTo("DisplayName=Red (Dark), Name=Dark.Red, Origin=ControlzEx.Showcase, IsHighContrast=False")); }
public ThemeResource(Theme theme, LibraryTheme libraryTheme, ResourceDictionary resourceDictionary, string?key, object?value) { this.Theme = theme; this.LibraryTheme = libraryTheme; this.Source = (resourceDictionary.Source?.ToString() ?? "Runtime").ToLower(); this.Source = CultureInfo.InstalledUICulture.TextInfo.ToTitleCase(this.Source) .Replace("Pack", "pack") .Replace("Application", "application") .Replace("Xaml", "xaml"); this.Key = key; this.Value = value switch { Color color => new SolidColorBrush(color), Brush brush => brush, _ => null }; this.StringValue = value?.ToString(); }
public void TestGetThemeName() { Assert.That(LibraryTheme.GetThemeName(new ResourceDictionary()), Is.Null.Or.Empty); Assert.That(LibraryTheme.GetThemeName(GenerateValidResourceDictionary()), Is.EqualTo("Generated")); }
public void TestMatches() { { var first = GenerateValidLibraryTheme(); var second = GenerateValidLibraryTheme(); Assert.That(first.Matches(second), Is.True); Assert.That(first.MatchesSecondTry(second), Is.False); Assert.That(first.MatchesThirdTry(second), Is.True); Assert.That(second.Matches(first), Is.True); Assert.That(second.MatchesSecondTry(first), Is.False); Assert.That(second.MatchesThirdTry(first), Is.True); } { var firstResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); firstResourceDictionary[Theme.ThemeIsHighContrastKey] = false; var first = new LibraryTheme(firstResourceDictionary, null); var secondResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); secondResourceDictionary[Theme.ThemeIsHighContrastKey] = true; var second = new LibraryTheme(secondResourceDictionary, null); Assert.That(first.Matches(second), Is.False); Assert.That(first.MatchesSecondTry(second), Is.False); Assert.That(first.MatchesThirdTry(second), Is.False); Assert.That(second.Matches(first), Is.False); Assert.That(second.MatchesSecondTry(first), Is.False); Assert.That(second.MatchesThirdTry(first), Is.False); } { var firstResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); firstResourceDictionary[Theme.ThemeIsHighContrastKey] = true; var first = new LibraryTheme(firstResourceDictionary, null); var secondResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); secondResourceDictionary[Theme.ThemeIsHighContrastKey] = false; var second = new LibraryTheme(secondResourceDictionary, null); Assert.That(first.Matches(second), Is.False); Assert.That(first.MatchesSecondTry(second), Is.False); Assert.That(first.MatchesThirdTry(second), Is.False); Assert.That(second.Matches(first), Is.False); Assert.That(second.MatchesSecondTry(first), Is.False); Assert.That(second.MatchesThirdTry(first), Is.False); } { var firstResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); firstResourceDictionary[Theme.ThemeIsHighContrastKey] = true; var first = new LibraryTheme(firstResourceDictionary, null); var secondResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); secondResourceDictionary[Theme.ThemeIsHighContrastKey] = true; var second = new LibraryTheme(secondResourceDictionary, null); Assert.That(first.Matches(second), Is.True); Assert.That(first.MatchesSecondTry(second), Is.False); Assert.That(first.MatchesThirdTry(second), Is.True); Assert.That(second.Matches(first), Is.True); Assert.That(second.MatchesSecondTry(first), Is.False); Assert.That(second.MatchesThirdTry(first), Is.True); } { var firstResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); firstResourceDictionary[Theme.ThemeColorSchemeKey] = "Generated with alternative"; var first = new LibraryTheme(firstResourceDictionary, null); var secondResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); var second = new LibraryTheme(secondResourceDictionary, null); Assert.That(first.Matches(second), Is.False); Assert.That(first.MatchesSecondTry(second), Is.False); Assert.That(first.MatchesThirdTry(second), Is.True); Assert.That(second.Matches(first), Is.False); Assert.That(second.MatchesSecondTry(first), Is.False); Assert.That(second.MatchesThirdTry(first), Is.True); } { var firstResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); firstResourceDictionary[Theme.ThemeColorSchemeKey] = "Generated with alternative"; var first = new LibraryTheme(firstResourceDictionary, null); var secondResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); secondResourceDictionary[Theme.ThemePrimaryAccentColorKey] = Colors.Blue; var second = new LibraryTheme(secondResourceDictionary, null); Assert.That(first.Matches(second), Is.False); Assert.That(first.MatchesSecondTry(second), Is.False); Assert.That(first.MatchesThirdTry(second), Is.False); Assert.That(second.Matches(first), Is.False); Assert.That(second.MatchesSecondTry(first), Is.False); Assert.That(second.MatchesThirdTry(first), Is.False); } { var firstResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); firstResourceDictionary[Theme.ThemeColorSchemeKey] = "Generated with alternative"; var first = new LibraryTheme(firstResourceDictionary, null); var secondResourceDictionary = GenerateValidRuntimeGeneratedResourceDictionary(); secondResourceDictionary[Theme.ThemePrimaryAccentColorKey] = Colors.Blue; secondResourceDictionary[LibraryTheme.LibraryThemeAlternativeColorSchemeKey] = "Generated with alternative"; var second = new LibraryTheme(secondResourceDictionary, null); Assert.That(first.Matches(second), Is.False); Assert.That(first.MatchesSecondTry(second), Is.False); Assert.That(first.MatchesThirdTry(second), Is.False); Assert.That(second.Matches(first), Is.False); Assert.That(second.MatchesSecondTry(first), Is.True); Assert.That(second.MatchesThirdTry(first), Is.False); } }
public ThemeResource(Theme theme, LibraryTheme libraryTheme, ResourceDictionary resourceDictionary, DictionaryEntry dictionaryEntry) : this(theme, libraryTheme, resourceDictionary, dictionaryEntry.Key.ToString(), dictionaryEntry.Value) { }