dotnet / dotnet/winforms

[Spec] Themes Implementation in Winforms

Open
#5,166 14 comments 13 reactions 1 assignee Claimed by @lonitra View on GitHub
api-suggestion area-Theming tenet-modernization
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

Please bring the ability of themes to winforms every other platform has it but WinForms.

We should be able to set the theme on startup and change it on the fly with a listener.

Should be something like this

services.configure(themeName);

This would then look in resources.resx for dark or light theme pallets. That could be used to style the entire application for example

DarkControlColor

There should also be some way of getting the value from here as some sort of enumeration query able. And be able to retrive the system colours once selected. Making it that the above is not necessary with the resources.

For example an internal enum that would pick up any custom themes the user has created.

NameSpace Suggestion:

Microsoft.WInforms.AppThemes

Enum Suggestion:

public enum AppThemeEnum
{
Unspecified,
Light,
Dark,
UserTheme
}

**Detect & Change User Interface Style**
DeviceInfo

| API | DESCRIPTION |
| -------------------------------- |----------------------------------------------------------------------------------------------------- |
| AppTheme CurrentAppTheme | What is the actual theme |
| AppTheme.ApplyTheme | This can be called from the this.ApplyTheme maybe they don't want all forms to be theme.|

The theme should also allow us to implement rounded corner where we could set a radius of the corner in what ever dpi the user wanted. Be it inches pixels cm mm.

Already
While this is implemented for xamrain it would give a clear conception of what is expected for the winforms flavour.

https://github.com/xamarin/Essentials/pull/927

VisualElement
AppThemeChanged Event

| API | DESCRIPTION
| ------------------------------------------------------------------- |---------------------------------------------------------------------- |
| void AppThemeChanged(AppThemeChangedEventArgs args) | Event that is fired whenever the app theme changed

public class AppThemeChangedEventArgs : EventArgs
{
public AppTheme RequestedTheme { get; }
}

To Apply the theme on a form one could or one could have a class derived from form for example

public class Form1 : ThemeForm
{

}
Resources could be based off Colours per app theme

Theme.AppTheme =AppThemeEnum.Dark

Availability
This should go into .net core,5 and 6.

![image](https://user-images.githubusercontent.com/5619229/123695216-3307d000-d852-11eb-87ca-c61cd11b4724.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.