Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change] Theming changed once more #811

Closed
batzen opened this issue May 28, 2020 · 12 comments
Closed

[Breaking change] Theming changed once more #811

batzen opened this issue May 28, 2020 · 12 comments
Assignees
Milestone

Comments

@batzen
Copy link
Member

batzen commented May 28, 2020

ThemeManager was moved from Fluent.Ribbon to ControlzEx.
This was done to be able to share one common ThemeManager between Fluent.Ribbon and MahApps.Metro.

This breaking change will be part of version 8.0.

@batzen batzen added this to the 8.0.0 milestone May 28, 2020
@batzen batzen self-assigned this May 28, 2020
@batzen batzen pinned this issue May 28, 2020
batzen added a commit that referenced this issue May 28, 2020
@pschimmel
Copy link
Contributor

Hi!
Does that influence the way the ThemeManager is used?
If I upgrade Fluent from version 7.0.1 to 8.0.0, will I have to change my code?

@batzen
Copy link
Member Author

batzen commented Jun 2, 2020

You will have to change your code as ThemeManger is no longer a static class. So you have to use ThemeManger.Current in 8.0.

@pschimmel
Copy link
Contributor

Hi!

To do some testing, I updated our application to version 8.0.0 today, but I did not manage to load the theme file. Before (version 7.0.1), Before, I loaded the theme at runtime from a resource file and switched to it:

ThemeManager.AddTheme(new Uri("pack://application:,,,/RibbonStuff;component/RibbonTheme.xaml"));
ThemeManager.ChangeTheme(Application.Current, "MyTheme");

In the new Manager the AddTheme overload that takes an Uri is not there anymore. What is the preferred way to accomplish the same?

@batzen
Copy link
Member Author

batzen commented Jul 27, 2020

That depends on what's in your theme and what you want to modify. Is it a complete theme, or did you use it to add additional things?

@pschimmel
Copy link
Contributor

pschimmel commented Jul 28, 2020

It is supposed to be an complete, independent theme, not containing anything else.
I basically took the file Theme.Template.xaml, renamed and modified it manually to match our color scheme.

@batzen
Copy link
Member Author

batzen commented Jul 28, 2020

Then it's quite easy and the following code should be enough:

var source = new Uri("pack://application:,,,/RibbonStuff;component/RibbonTheme.xaml");
var newTheme = new Theme(new LibraryTheme(source, null));
ThemeManager.Current.ChangeTheme(Application.Current, newTheme);

@pschimmel
Copy link
Contributor

pschimmel commented Jul 28, 2020

Thank you for the quick response.

When using your code snippet, I first got an exception in RuntimeThemeGenerator, line 100.

In the ControlzEx source code, I saw that the problem is that the BaseColor is not set and I added the following lines to my RibbonTheme.xaml file:

<system:String x:Key="Theme.BaseColorScheme">Light</system:String>
<system:String x:Key="Theme.ColorScheme">Blue</system:String>
<system:String x:Key="Theme.AlternativeColorScheme">Amber</system:String>

I had no idea what to put there, so I just picked names from the built-in themes.

Then there is no exception anymore and Ribbon resources are added to the resources of my application. However the resources defined in my theme are not used.

To test this, I defined the Fluent.Ribbon.Brushes.Button.MouseOver.Background brush with a green color, but the value contained in the resource dictionary is #330078D7.

Are the defined values for BaseColorScheme and so on OK?

As I don't really have to change the theme at runtime, I just added the ribbon resources to the merged dictionary of my application and it worked for me, but the behavior is still strange.

@batzen
Copy link
Member Author

batzen commented Jul 28, 2020

At which level do you load the regular ribbon resources? If it's on the window level you have to change the theme there and not on the application level, which i suggested.
Could you also check the return value of ChangeTheme? It should return your newly applied theme on success.
If your issue persists a repro would help.

@pschimmel
Copy link
Contributor

I'm setting the resources only once, on the application level.
The theme returned by ChangeTheme also contains the wrong colors.

@batzen
Copy link
Member Author

batzen commented Jul 30, 2020

Could you create a small repro then?

@pschimmel
Copy link
Contributor

Here's the repo:

FluentTest_Theming.zip

Just start the application it will show two message boxes containing one sample color.
After creating the theme, the sample color I added is OK.
But after changing the theme, that color is not used.

@batzen
Copy link
Member Author

batzen commented Aug 3, 2020

Ah, ok.
That's because you have to use var newTheme = new Theme(new LibraryTheme(source, RibbonLibraryThemeProvider.DefaultInstance)); passing RibbonLibraryThemeProvider.DefaultInstance here is important as otherwise the ThemeManager thinks your theme is for a different component and provides a theme that matches Theme.BaseColorScheme and Theme.ColorScheme from RibbonLibraryThemeProvider.DefaultInstance.
I forgot to mention that when posting my sample code.
Beside that, your theme is not complete and is missing things like WhiteColor, BlackColor etc. ;-)

@batzen batzen closed this as completed Sep 19, 2020
@batzen batzen unpinned this issue Sep 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants