-
Notifications
You must be signed in to change notification settings - Fork 986
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
Add Dark Mode Visual Style Theme Subclass #11985
base: main
Are you sure you want to change the base?
Conversation
…orted Windows Registry Key may be deleted and never restored and may be exist and there is no dark mode subclass in aero.msstyles
@dotnet-policy-service agree
في الأحد، ٢٥ أغسطس ٢٠٢٤ ٨:٤٩ م dotnet-policy-service[bot] <
***@***.***> كتب:
(Translation: on Sun، 25 August 2024 8:49 PM dotnet-policy-service[bot] < ***@***.***> wrote:)
… Assigned #11985 <#11985> to
@memoarfaa <https://github.com/memoarfaa>.
—
Reply to this email directly, view it on GitHub
<#11985 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC7KK2CGY675YZFK4S663ZDZTIKK5AVCNFSM6AAAAABNCXIQDKVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJUGAYDIOJSGYYTAOI>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
...tem.Windows.Forms/src/System/Windows/Forms/Controls/DataGridView/DataGridViewCheckBoxCell.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/Controls/ComboBox/ComboBoxRenderer.cs
Outdated
Show resolved
Hide resolved
@@ -17,7 +17,11 @@ public partial class DataGridViewButtonCell : DataGridViewCell | |||
private static readonly int s_propButtonCellFlatStyle = PropertyStore.CreateKey(); | |||
private static readonly int s_propButtonCellState = PropertyStore.CreateKey(); | |||
private static readonly int s_propButtonCellUseColumnTextForButtonValue = PropertyStore.CreateKey(); | |||
private static readonly VisualStyleElement s_buttonElement = VisualStyleElement.Button.PushButton.Normal; | |||
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | |||
private static readonly VisualStyleElement s_darkButtonElement = VisualStyleElement.CreateElement("DarkMode_Explorer::BUTTON", 1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, instead of hardcoding "DarkMode_Explorer" it should be an interpolated const, e.g.: {DarkModeIdentifier}_{Explorer}
.
See:
winforms/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Lines 162 to 165 in 14acefa
internal const string DarkModeIdentifier = "DarkMode"; | |
internal const string ExplorerThemeIdentifier = "Explorer"; | |
internal const string ItemsViewThemeIdentifier = "ItemsView"; | |
internal const string ComboBoxButtonThemeIdentifier = "CFD"; |
If any more consts need adding - they should be added here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, does that look good now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I do not see that you changed anything.
Can you make the changes?
src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabRenderer.cs
Outdated
Show resolved
Hide resolved
src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs
Outdated
Show resolved
Hide resolved
@KlausLoeffelmann @JeremyKuhne @merriemcgaw @lonitra - if this fixes the rendering issue, this change would be a great addition to the .NET 9 release. |
As long as I can use the new API to set color mode on my entire application from my settings form at runtime at any time to switch between light and dark mode I would be happy in the .NET 9 release. Also what about all of the system menus in all the possible controls as well? Are they dark themed with this change now or do I have to go into black magic to convert them to |
src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs
Show resolved
Hide resolved
@@ -379,21 +377,9 @@ private static int GetSystemColorModeInternal() | |||
return SystemDarkModeDisabled; | |||
} | |||
|
|||
int systemColorMode = SystemDarkModeDisabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're still discussing, if we can take this for .NET 9 RC2 (the bar is service, and we would need to consider this a bug fix). So, this particular change, we would probably not want to take. @merriemcgaw, @lonitra.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be as it is, please revert this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please also update the description to provide a visual of the before/after of this change?
src/System.Windows.Forms/src/System/Windows/Forms/VisualStyles/VisualStyleRenderer.cs
Outdated
Show resolved
Hide resolved
…/VisualStyleRenderer.cs Co-authored-by: Loni Tra <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11985 +/- ##
===================================================
+ Coverage 75.03366% 75.06842% +0.03476%
===================================================
Files 3063 3063
Lines 632075 632114 +39
Branches 46784 46800 +16
===================================================
+ Hits 474269 474518 +249
+ Misses 154431 154218 -213
- Partials 3375 3378 +3
Flags with carried forward coverage won't be shown. Click here to find out more. |
…Control/TabRenderer.cs Co-authored-by: Igor Velikorossov <[email protected]>
@@ -17,7 +17,11 @@ public partial class DataGridViewButtonCell : DataGridViewCell | |||
private static readonly int s_propButtonCellFlatStyle = PropertyStore.CreateKey(); | |||
private static readonly int s_propButtonCellState = PropertyStore.CreateKey(); | |||
private static readonly int s_propButtonCellUseColumnTextForButtonValue = PropertyStore.CreateKey(); | |||
private static readonly VisualStyleElement s_buttonElement = VisualStyleElement.Button.PushButton.Normal; | |||
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | |||
private static readonly VisualStyleElement s_darkButtonElement = VisualStyleElement.CreateElement("DarkMode_Explorer::BUTTON", 1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this was missed
private static readonly VisualStyleElement s_darkButtonElement = VisualStyleElement.CreateElement("DarkMode_Explorer::BUTTON", 1, 1); | |
private static readonly VisualStyleElement s_darkButtonElement = VisualStyleElement.CreateElement($"{Control.DarkModeIdentifier}_{Control.ExplorerThemeIdentifier}::BUTTON", 1, 1); |
/// <summary> | ||
/// <para> | ||
/// Gets a value specifying whether the operating system has Dark Mode visual styles subclass and the Application can use this subclass to draw controls with Dark Mode theme. | ||
///</para> | ||
///<para> | ||
///<return> | ||
///<para> Returns true if Visual Style Dark Mode subclass is: </para> | ||
/// <para> 1) Supported by the operating system.</para> | ||
/// <para> 2) Enabled in the client area.</para> | ||
/// <para> 3) operating system not ruining in high contrast mode</para> | ||
/// <para> Otherwise, returns false. Note that if false is returned, attempts to create/use objects of this class will throw exceptions.</para> | ||
///</return> | ||
///</para> | ||
/// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <summary> | |
/// <para> | |
/// Gets a value specifying whether the operating system has Dark Mode visual styles subclass and the Application can use this subclass to draw controls with Dark Mode theme. | |
///</para> | |
///<para> | |
///<return> | |
///<para> Returns true if Visual Style Dark Mode subclass is: </para> | |
/// <para> 1) Supported by the operating system.</para> | |
/// <para> 2) Enabled in the client area.</para> | |
/// <para> 3) operating system not ruining in high contrast mode</para> | |
/// <para> Otherwise, returns false. Note that if false is returned, attempts to create/use objects of this class will throw exceptions.</para> | |
///</return> | |
///</para> | |
/// </summary> | |
/// <summary> | |
/// Gets a value specifying whether the operating system has Dark Mode visual styles subclass and the Application can use this subclass to draw controls with Dark Mode theme. | |
///</summary> | |
/// <return> | |
/// <see langword="true"/> if Visual Style Dark Mode subclass is supported by the operating system, | |
/// enabled in the client area, and operating system not running high contrast mode. | |
/// Otherwise, returns <see langword="false"/>. Note that if <see langword="false"/> is returned, attempts to create/use objects of this class will throw exceptions. | |
/// </return> |
///</para> | ||
/// </summary> | ||
[Experimental(DiagnosticIDs.ExperimentalDarkMode, UrlFormat = DiagnosticIDs.UrlFormat)] | ||
public static bool IsDarkModeSupported |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point we cannot add new public API for net 9 RC2. Does this need to be public to fix rendering issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @memoarfaa,
I have a couple of additional issues which need to be addressed - most of them are just using consts for the theme names, so nothing big.
That said, while we would need to take a closer look at your proposed additional API for .NET 10, we cannot take that in RC2 for .NET 9 since we're way past code complete. Also, for new APIs, we need to bring that to the API review board, and it has to be officially discussed and then agreed to.
If you can do these changes on short notice, that would be nice, because the cut-of-date is approaching, and you bug fix would need to be tested before!
Thanks so much for doing this - we really appreciate!!
@@ -3320,6 +3320,7 @@ static System.Windows.Forms.VisualStyles.VisualStyleInformation.Url.get -> strin | |||
static System.Windows.Forms.VisualStyles.VisualStyleInformation.Version.get -> string! | |||
static System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(System.Windows.Forms.VisualStyles.VisualStyleElement! element) -> bool | |||
static System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsSupported.get -> bool | |||
static System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsDarkModeSupported.get -> bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot take new APIs at this point. So, this needs to be reverted.
@@ -379,21 +377,9 @@ private static int GetSystemColorModeInternal() | |||
return SystemDarkModeDisabled; | |||
} | |||
|
|||
int systemColorMode = SystemDarkModeDisabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be as it is, please revert this.
{ | ||
} | ||
|
||
return systemColorMode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here - we need to keep this.
private static readonly VisualStyleElement s_comboBoxElement = VisualStyleElement.ComboBox.DropDownButton.Normal; | ||
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
private static readonly VisualStyleElement s_comboBoxElement = Application.IsDarkModeEnabled | ||
? VisualStyleElement.CreateElement($"{Control.DarkModeIdentifier}_{Control.ComboBoxButtonThemeIdentifier}::COMBOBOX", 1, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you introduce a const for COMBOBOX
as well?
@@ -17,7 +17,11 @@ public partial class DataGridViewButtonCell : DataGridViewCell | |||
private static readonly int s_propButtonCellFlatStyle = PropertyStore.CreateKey(); | |||
private static readonly int s_propButtonCellState = PropertyStore.CreateKey(); | |||
private static readonly int s_propButtonCellUseColumnTextForButtonValue = PropertyStore.CreateKey(); | |||
private static readonly VisualStyleElement s_buttonElement = VisualStyleElement.Button.PushButton.Normal; | |||
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | |||
private static readonly VisualStyleElement s_darkButtonElement = VisualStyleElement.CreateElement("DarkMode_Explorer::BUTTON", 1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I do not see that you changed anything.
Can you make the changes?
|
||
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
private static readonly VisualStyleElement s_comboBoxReadOnlyButton = Application.IsDarkModeEnabled | ||
? VisualStyleElement.CreateElement($"{Control.DarkModeIdentifier}_{Control.ComboBoxButtonThemeIdentifier}::COMBOBOX", 5, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here! 😸
private static readonly VisualStyleElement s_headerElement = VisualStyleElement.Header.Item.Normal; | ||
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
private static readonly VisualStyleElement s_headerElement = Application.IsDarkModeEnabled | ||
? VisualStyleElement.CreateElement($"{Control.DarkModeIdentifier}_{Control.ItemsViewThemeIdentifier}::Header", 1, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the "Header".
private static readonly VisualStyleElement s_headerElement = VisualStyleElement.Header.Item.Normal; | ||
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
private static readonly VisualStyleElement s_headerElement = Application.IsDarkModeEnabled | ||
? VisualStyleElement.CreateElement($"{Control.DarkModeIdentifier}_{Control.ItemsViewThemeIdentifier}::Header", 1, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here! 😺
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
if (Application.IsDarkModeEnabled) | ||
{ | ||
PInvoke.SendMessage(tooltipHwnd, PInvoke.TTM_SETWINDOWTHEME, default, "DarkMode_Explorer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the existing const here?
{ | ||
get | ||
{ | ||
bool supported = AreClientAreaVisualStylesSupported; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too invasive a change this late in the game.
Can we revert this to the existing method, because that had been tested exhaustively?
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
if (Application.IsDarkModeEnabled && GetStyle(ControlStyles.ApplyThemingImplicitly)) | ||
{ | ||
_ = PInvoke.SetWindowTheme( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not all tabs can be shown at once, the tab control will display an up-down control that will also need to be styled.
This is an improvement to new Dark Mode experimental feature
#11857
see
https://learn.microsoft.com/en-us/windows/win32/controls/theme-subclasses#two-ways-to-use-a-theme-subclass
Fixes #11893.
Fixes #11953.
Microsoft Reviewers: Open in CodeFlow