We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Theme manager crashing with custom Window types

Hello,

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?


Thanks!






6 Replies

KA Karthick Arjunan Syncfusion Team April 26, 2023 02:32 PM UTC

Hi Matthew,

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.


Regards,
Karthick Arjunan


Attachment: CustomWindowThemeDemo_8f1944a6.zip


MA Matthew April 26, 2023 03:43 PM UTC

Hi Karthick,


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.


Thanks!


Attachment: CustomWindowThemeDemo_3571ae37.zip


MA Matthew June 14, 2023 03:37 PM UTC

Hi Karthick,


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?


Thanks!







KA Karthick Arjunan Syncfusion Team June 15, 2023 02:35 PM UTC

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.


Code snippets:

 public partial class MainWindow : Window

    {

        CustomWindow customWindow = new CustomWindow();

        public MainWindow()

        {

            InitializeComponent();

            SfSkinManager.SetTheme(this, new Theme("MaterialDark"));

            SfSkinManager.SetTheme(customWindow, new Theme("MaterialDark"));

        }

 

        private void Button_Click(object sender, RoutedEventArgs e)

        {

            customWindow.ShowDialog();

        }

    }


Attachment: CustomWindowThemeDemo__259444d3.zip


MA Matthew June 15, 2023 03:25 PM UTC

Hi Karthick,


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.


Thanks!

Matt




KA Karthick Arjunan Syncfusion Team June 20, 2023 01:34 PM UTC

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.


Attachment: CustomWindowThemeDemo___9c72cbcd.zip

Loader.
Live Chat Icon For mobile
Up arrow icon