I have an application with different controls inheriting from Window.
When I try to apply a theme to a custom Window:
SfSkinManager.SetTheme(CustomWindow, new Theme("MaterialDark"));
I receive the error "An item with the same key has already been added. Key: Window" from Syncfusion.SfSkinManager.WindowHelper.GetWindowInfo().
Are there any workarounds or solutions for applying theming to custom Window controls?
We have created a simple sample and applied the theme to the custom window. Please check the attached sample and let us know if you have any concerns.
Thanks so much for your fast reply. The error happens specifically when using a custom control that inherits from Window, not as show in the sample. I added in a CustomWindowThemeDemoNET7 project (I also wanted to test it in the latest .NET). When I click "Click" this is the error:
I attached the updated sample - let me know if that works for you.
It looks like your reply was deleted:
We were able to reproduce the reported issue. Currently, we are validating the reported query we will update the complete details on or before May 02, 2023.
Do you have any updates on this issue?
To resolve this, apply the required theme to the custom window in the MainWindow.xaml, we have attached the code snippet for your reference. Also, we have attached a modified sample. Please check the sample and let us know your concern.
public partial class MainWindow : Window
CustomWindow customWindow = new CustomWindow();
SfSkinManager.SetTheme(this, new Theme("MaterialDark"));
SfSkinManager.SetTheme(customWindow, new Theme("MaterialDark"));
private void Button_Click(object sender, RoutedEventArgs e)
I really appreciate your response. The sample you sent is still showing the error - is it working for you?
Storing references to child windows rather than creating them as needed is also problematic. When the window is opened a second time it will throw an InvalidOperationException due to it being reused.
We have attached the modified sample which works fine and we also attached the demo video for your reference. Please check the attached sample and let us know your concern.