How to apply the theme colors to custom UserControls?

I'm using themes in my app with SkinManager.ApplicationVisualTheme("HighContrastBlack"). How can I apply the colors of the theme to my own UserControls?

For doing this, I need a way to get the colors of the HighContrastBlack Theme like "Background", "Text Color", "Selected Background", "Selected Text", "Button Background", "Button Text", "Hyperlink Color" and "Disabled Text".

I want to use the colors, to colorize my UserControl.

Additional, I would like to create my own themes, based on the HighContrastBlack theme and import them. Then I need the self configured colors from the by the Theme Studio exported .dll file.


15 Replies

SN Sudharsan Narayanan Syncfusion Team November 7, 2023 03:09 PM UTC

Hi Nils Hoyer,

We have prepared the sample to achieve your requirement to apply the theme colors to Custom UserControl. Please find the sample below.

Please check the sample. If we misunderstood the query, please provide more details about the requirement, or modify our sample and revert to us. So, it will be helpful to prompt the solution on further. 

Regards,

Sudharsan


Attachment: CustomUserControl_86ee9dc8.zip


UN Unknown November 7, 2023 05:24 PM UTC

I'm sorry, I posted in the wrong forum. I'm using WinForms, not WPF.😪



SG Santhosh Govindasamy Syncfusion Team November 8, 2023 04:58 PM UTC

Nils Hoyer,

We are currently analyzing your reported scenario. We need time to validate the scenario, we will provide an update on or before November 10, 2023.


Regards,
Santhosh.G



SG Santhosh Govindasamy Syncfusion Team November 10, 2023 06:07 PM UTC

Nils Hoyer,

We have prepared the sample to meet your requirement of applying the theme to Custom UserControl. Please find the sample below.

We would like to inform you that we do not have an implementation to set the theme for the entire application and we also do not set the theme for framework controls.

To set the theme for a user control, you must implement Syncfusion-related controls in your user control.


Here we have attached the tested sample . Please have a look at this. If you have further query please provide details or modify the attached sample based on your scenario. It will be helpful for us to proceed further.
 


Attachment: CustomUserControl_f7a857af.zip


UN Unknown November 12, 2023 04:48 PM UTC

You misunderstood me. Your example shows, how to add a Syncfusion control into my UserControl.

But I have UserControls with my own paint method, based on System.Drawing.Graphics.

To draw them in the HighContrastBlack theme colors, I need to know them.



DD Dhivyabharathi Dakshinamurthy Syncfusion Team November 13, 2023 03:21 PM UTC

Hi Nils Hoyer,

If you're using controls from the Syncfusion library, you can easily set and apply themes to those controls. However, when it comes to user controls that are not part of the Syncfusion library, the functionality to apply themes directly to these controls might not be available, so it's not possible to apply themes to any other user controls.


Regards,

DhivyaBharathi Dakshinamurthy



UN Unknown November 13, 2023 03:23 PM UTC

Thank you for your answer.

Maybe you can implement a solution for this?



SD Swathi Dhatchanamoorthi Syncfusion Team November 14, 2023 05:27 PM UTC

Hi Nils Hoyer,


We are implementing theme support for our controls at the source level. however, providing theme support for custom controls was not possible.


Regards,
Swathi D



UN Unknown November 16, 2023 07:09 AM UTC

I did not ask you to implement theme support for custom controls. Indeed, you can't do this.

But if you offer a way for me to get the theme colors, since I asked about in this thread, I would be able to do this.

So once again: Can you implement a solution, that I can get the theme colors of the selected theme?



MS Madhavan Sathapillai Syncfusion Team November 17, 2023 04:17 PM UTC

Hi Nils Hoyer,


We have used the colors in our control themes that are based on System HighContrast themes. Please refer the attached picture, and we suggest you try using them in your case as well. 


Regards,
Madhavan S


Attachment: System_Themes_3a2e8059.zip


UN Unknown November 17, 2023 04:21 PM UTC

Yes, indeed, I can use hard-coded colors. But if you change your theme in the future or if I use another of your themes, I have to change my code again.

Why don't you understand, that this is a bad solution?

Why don't you want to implement a good solution into your software?



SG Santhosh Govindasamy Syncfusion Team November 20, 2023 05:00 PM UTC

Nils Hoyer,

We kindly inform you that we don't have direct color implementation for the themes. Instead, we maintain the colors as specified in the control. For example, if you use SfButton in your application with the theme set to "HighContrastBlack," based on the theme, we maintain the colors in the SfButton control, such as "PressedBackColor" being light gray and "BorderColor" being black.

We maintain the color on a control-by-control basis. For your reference, please find the below code snippet.

<Properties Font="Microsoft San Serif;8.25;Regular" />

    <Elements BackColor="#000000" DisabledBackColor="#000000" HoverBackColor="#00EFFF" PressedBackColor="#00EFFF" FocusedBackColor="#000000" ForeColor="#FFFFFF" HoverForeColor="#000000" PressedForeColor="#000000" FocusedForeColor="#FFFFFF" DisabledForeColor="#00F800" BorderColor="#FFFFFF" HoverBorderColor="#00EFFF" PressedBorderColor="#00EFFF" DisabledBorderColor="#00F800" FocusedBorderColor="#00EFFF">

    </Elements>



UN Unknown November 21, 2023 08:40 AM UTC

I found the answer to my question: I need to create the control, I want to get the colors from. For example, your SfButton. After creating it, I can access to his colors, like BackColor, DisabledBackColor, HoverBackColor and so on of your snippet with this code:

var sfButton = new SfButton();

var backColor = sfButton.Style.BackColor;

var disabledBackColor = sfButton.Style.DisabledBackColor;

var hoverBackColor = sfButton.Style.HoverBackColor;

So the answer to my question is very simple, but you were not able to give it.



UN Unknown November 21, 2023 01:12 PM UTC

I found the colors, I want to use, except the "Hyperlink Color", configurable in the High Contrust Black theme.

Which control does it use?


Unbenannt.png



SG Santhosh Govindasamy Syncfusion Team November 22, 2023 01:44 PM UTC

Nils Hoyer,

Based on our understanding, you intended to use those colors, except for the 'HyperLink color.' For your information, we haven't disabled the 'HyperLink color' option; this one is the default setting. The hyperlink color is only applied to hyperlink text, such as in the Theme Studio grid control, which contains hyperlink text in the Url column. When you set the hyperlink color to white, it doesn't make any difference in your application.
please refer the document


Attachment: HyperLink_2fbd7a2a.zip

Loader.
Up arrow icon