Colorful generation #1163
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
That's currently not possible during runtime with the default Are you trying to generate one during runtime or during compile time? If you want it during runtime you can do it as follows:
and use it as
The modified part is (and it's usage one line later)
the remaining code is just a copy from the default implementation. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much Bastian !
I just need to point out that the Color keys has been changed since the version 10 (I don’t know really witch one).
Then
ThemeGenerator.Colors.PrimaryAccentColor", runtimeThemeColorValues.PrimaryAccentColor.ToString()
Beccome
ThemeGenerator.Colors.PrimaryAccent", runtimeThemeColorValues.PrimaryAccent.ToString()
All Color word at the end of each keys has been removed.
And I belive that it’s the same with ColorBrushes keys, but I’m not sure, I don’t remember exactly.
But anyway, Thank you so much !
Yannick Lalbatry
Gérant
SOFIASI
image024.png
***@***.***> ***@***.***
image025.png
<tel:+33285523060> +33 2 85 52 30 60
image026.png
<tel:+33781005404> +33 7 81 00 54 04
image027.png
5, Boulevard Vincent Gache
44200 Nantes
image028.png
<http://sofiasi.com/> sofiasi.com
<https://sofiasi.com/> image029.png
***@***.***> image030.png
<https://www.facebook.com/profile.php?id=100063733312806> image031.png
De : Bastian Schmidt ***@***.***
Envoyé : dimanche 10 septembre 2023 10:22
À : fluentribbon/Fluent.Ribbon
Cc : yannicklal; Author
Objet : Re: [fluentribbon/Fluent.Ribbon] Colorful generation (Discussion #1163)
That's currently not possible during runtime with the default RuntimeThemeGenerator.
You could write your own, to achieve that.
Are you trying to generate one during runtime or during compile time?
If you want it during runtime you can do it as follows:
private class RuntimeThemeGeneratorWithColorVariant : RuntimeThemeGenerator
{
private static bool initialized = false;
public static void Initialize()
{
if (initialized)
{
return;
}
Current = new RuntimeThemeGeneratorWithColorVariant();
initialized = true;
}
public string? ColorSchemeVariant { get; set; }
/// <inheritdoc />
public override LibraryTheme GenerateRuntimeLibraryTheme(LibraryThemeProvider libraryThemeProvider, Dictionary<string, string> values, RuntimeThemeColorValues runtimeThemeColorValues, string themeTemplateContent, string themeName, string themeDisplayName, ThemeGenerator.ThemeGeneratorBaseColorScheme baseColorScheme, ThemeGenerator.ThemeGeneratorColorScheme colorScheme, ThemeGenerator.ThemeGeneratorParameters generatorParameters)
{
values.Add("ThemeGenerator.Colors.PrimaryAccentColor", runtimeThemeColorValues.PrimaryAccentColor.ToString());
values.Add("ThemeGenerator.Colors.AccentBaseColor", runtimeThemeColorValues.AccentBaseColor.ToString());
values.Add("ThemeGenerator.Colors.AccentColor80", runtimeThemeColorValues.AccentColor80.ToString());
values.Add("ThemeGenerator.Colors.AccentColor60", runtimeThemeColorValues.AccentColor60.ToString());
values.Add("ThemeGenerator.Colors.AccentColor40", runtimeThemeColorValues.AccentColor40.ToString());
values.Add("ThemeGenerator.Colors.AccentColor20", runtimeThemeColorValues.AccentColor20.ToString());
values.Add("ThemeGenerator.Colors.HighlightColor", runtimeThemeColorValues.HighlightColor.ToString());
values.Add("ThemeGenerator.Colors.IdealForegroundColor", runtimeThemeColorValues.IdealForegroundColor.ToString());
libraryThemeProvider.FillColorSchemeValues(values, runtimeThemeColorValues);
var variant = this.ColorSchemeVariant is null
? new ThemeGenerator.AdditionalColorSchemeVariant()
: generatorParameters.AdditionalColorSchemeVariants.First(x => x.Name == this.ColorSchemeVariant);
var xamlContent = ThemeGenerator.Current.GenerateColorSchemeFileContent(themeTemplateContent, themeName, themeDisplayName, baseColorScheme.Name, colorScheme.Name, colorScheme.Name, runtimeThemeColorValues.Options.IsHighContrast, colorScheme.Values, variant.Values, baseColorScheme.Values, generatorParameters.DefaultValues);
var preparedXamlContent = libraryThemeProvider.PrepareXamlContent(this, xamlContent, runtimeThemeColorValues);
var resourceDictionary = (ResourceDictionary)XamlReader.Parse(preparedXamlContent);
resourceDictionary.Add(Theme.ThemeIsRuntimeGeneratedKey, true);
resourceDictionary[Theme.ThemeIsHighContrastKey] = runtimeThemeColorValues.Options.IsHighContrast;
resourceDictionary[LibraryTheme.RuntimeThemeColorValuesKey] = runtimeThemeColorValues;
libraryThemeProvider.PrepareRuntimeThemeResourceDictionary(this, resourceDictionary, runtimeThemeColorValues);
var runtimeLibraryTheme = libraryThemeProvider.CreateRuntimeLibraryTheme(resourceDictionary, runtimeThemeColorValues);
return runtimeLibraryTheme;
}
}
and use it as
RuntimeThemeGeneratorWithColorVariant.Initialize();
((RuntimeThemeGeneratorWithColorVariant)RuntimeThemeGenerator.Current).ColorSchemeVariant = "Colorful";
var theme = RuntimeThemeGenerator.Current.GenerateRuntimeTheme(baseColorScheme, accentBaseColor)!;
The modified part is (and it's usage one line later)
var variant = this.ColorSchemeVariant is null
? new ThemeGenerator.AdditionalColorSchemeVariant()
: generatorParameters.AdditionalColorSchemeVariants.First(x => x.Name == this.ColorSchemeVariant);
the remaining code is just a copy from the default implementation.
—
Reply to this email directly, view it on GitHub <#1163 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJO5VHKYQMKEALNLS6ZONMTXZV2BLANCNFSM6AAAAAA36F77RA> .
You are receiving this because you authored the thread. <https://github.com/notifications/beacon/AJO5VHMJWU3T7M5IKG7SRY3XZV2BLA5CNFSM6AAAAAA36F77RCWGG33NNVSW45C7OR4XAZNRIRUXGY3VONZWS33OINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQANIXQC.gif> Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
That's currently not possible during runtime with the default
RuntimeThemeGenerator
.You could write your own, to achieve that.
Are you trying to generate one during runtime or during compile time?
If you want it during runtime you can do it as follows: