You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make readme look better when pasted into NuGet Gallery. Still not completely compatible, because NuGet Gallery can't handle the image in the title, and having the title and version listed twice is redundant, so won't be packing the readme into the package using PackageReadmeFile.
@@ -26,7 +27,7 @@ Enable native Windows dark mode for your WPF and Windows Forms title bars.
26
27
-[Before showing a new window](#before-showing-a-new-window-1)
27
28
-[After showing a window](#after-showing-a-window-1)
28
29
-[Complete example](#complete-example-1)
29
-
-[Raw HWND](#raw-hwnd)
30
+
-[HWND](#hwnd)
30
31
-[Taskbar theme](#taskbar-theme)
31
32
-[Demos](#demos)
32
33
-[WPF](#wpf-1)
@@ -36,7 +37,6 @@ Enable native Windows dark mode for your WPF and Windows Forms title bars.
36
37
37
38
<!-- /MarkdownTOC -->
38
39
39
-
<aid="requirements"></a>
40
40
## Requirements
41
41
42
42
- .NET runtime
@@ -49,7 +49,6 @@ Enable native Windows dark mode for your WPF and Windows Forms title bars.
49
49
- You can still run your program on earlier Windows versions as well, but the title bar won't turn dark
50
50
- Windows Presentation Foundation, Windows Forms, or access to the native window handle of other windows in your process
51
51
52
-
<aid="installation"></a>
53
52
## Installation
54
53
55
54
[DarkNet is available in NuGet Gallery.](https://www.nuget.org/packages/DarkNet/)
@@ -61,18 +60,14 @@ dotnet add package DarkNet
61
60
Install-Package DarkNet
62
61
```
63
62
64
-
<aid="usage"></a>
65
63
## Usage
66
64
67
-
<aid="basics"></a>
68
65
### Basics
69
66
70
-
<aid="entry-point"></a>
71
67
#### Entry point
72
68
73
69
The top-level interface of this library is **`Dark.Net.IDarkNet`**, which is implemented by the **`DarkNet`** class. A shared instance of this class is available from **`DarkNet.Instance`**, or you can construct a new instance with `new DarkNet()`.
74
70
75
-
<aid="methods"></a>
76
71
#### Methods
77
72
78
73
1. First, you may optionally call **`SetCurrentProcessTheme(Theme)`** to define a default theme for your windows, although it doesn't actually apply the theme to any windows on its own.
@@ -81,17 +76,14 @@ The top-level interface of this library is **`Dark.Net.IDarkNet`**, which is imp
81
76
82
77
If you don't call this method, any window on which you call `SetWindowTheme*(myWindow, Theme.Auto)` will inherit its theme from the operating system's default app theme, skipping this app-level default.
83
78
2. Next, you must call one of the **`SetWindowTheme*`** methods to actually apply a theme to each window. There are three methods to choose from, depending on what kind of window you have:
If you don't call one of these methods on a given window, that window will always use the light theme, even if you called `SetCurrentProcessTheme` and set the OS default app mode to dark.
91
84
92
85
*These are three separate methods instead of one overloaded method in order to prevent apps from having to depend on **both** WPF and Windows Forms when they only intend to use one, because an overloaded method signature can't be resolved when any of the parameters' types are missing.*
93
86
94
-
<aid="themes"></a>
95
87
#### Themes
96
88
97
89
This library uses the `Theme` enum to differentiate **`Dark`** mode from **`Light`** mode. You can set any window in your application to use whichever theme you want, they don't all have to be the same theme.
@@ -108,10 +100,8 @@ If your app is running with the `Auto` theme at both the window and process leve
108
100
109
101
Try the [demo apps](#demos) to see this behavior in action.
110
102
111
-
<aid="wpf"></a>
112
103
### WPF
113
104
114
-
<aid="on-application-startup"></a>
115
105
#### On application startup
116
106
117
107
Before showing **any** windows in your application, you may optionally call
@@ -136,7 +126,6 @@ public partial class App: Application {
136
126
}
137
127
```
138
128
139
-
<aid="before-showing-a-new-window"></a>
140
129
#### Before showing a new window
141
130
142
131
Before showing **each** window in your application, you have to set the theme for that window.
@@ -165,22 +154,18 @@ public partial class MainWindow {
165
154
166
155
You must perform this step for **every** window you show in your application, not just the first one.
167
156
168
-
<aid="after-showing-a-window"></a>
169
157
#### After showing a window
170
158
171
159
After calling `SetWindowThemeWpf` for the first time and showing a new window, you may optionally make additional calls to `SetCurrentProcessTheme` or `SetWindowThemeWpf` multiple times to change the theme later. This is useful if you let users choose a theme in your app's settings.
172
160
173
161
Try the [demo apps](#demos) to see this behavior in action.
174
162
175
-
<aid="complete-example"></a>
176
163
#### Complete example
177
164
178
165
See the demo [`App.xaml.cs`](https://github.com/Aldaviva/DarkNet/blob/master/darknet-demo-wpf/App.xaml.cs) and [`MainWindow.xaml.cs`](https://github.com/Aldaviva/DarkNet/blob/master/darknet-demo-wpf/MainWindow.xaml.cs).
179
166
180
-
<aid="windows-forms"></a>
181
167
### Windows Forms
182
168
183
-
<aid="on-application-startup-1"></a>
184
169
#### On application startup
185
170
186
171
Before showing **any** windows in your application, you may optionally call
@@ -205,7 +190,6 @@ internal static class Program {
205
190
}
206
191
```
207
192
208
-
<aid="before-showing-a-new-window-1"></a>
209
193
#### Before showing a new window
210
194
211
195
Before showing **each** window in your application, you have to set the theme for that window.
You must perform this step for **every** window you show in your application, not just the first one.
225
209
226
-
<aid="after-showing-a-window-1"></a>
227
210
#### After showing a window
228
211
229
212
After calling `SetWindowThemeForms` for the first time and showing a new window, you may optionally make additional calls to `SetCurrentProcessTheme` or `SetWindowThemeForms` multiple times to change the theme later. This is useful if you let users choose a theme in your app's settings.
230
213
231
214
Try the [demo apps](#demos) to see this behavior in action.
232
215
233
-
<aid="complete-example-1"></a>
234
216
#### Complete example
235
217
236
218
```cs
@@ -256,47 +238,40 @@ internal static class Program {
256
238
257
239
See also the demo [`Program.cs`](https://github.com/Aldaviva/DarkNet/blob/master/darknet-demo-winforms/Program.cs) and [`Form1.cs`](https://github.com/Aldaviva/DarkNet/blob/master/darknet-demo-winforms/Form1.cs).
258
240
259
-
<aid="raw-hwnd"></a>
260
-
### Raw HWND
241
+
### HWND
261
242
262
-
If you want to change the theme of a window in your application that was not created with WPF or Windows Forms, you can also just pass the HWND of the window to `SetWindowThemeRaw(IntPtr, Theme)`.
243
+
If you want to change the theme of a window in your application that was not created with WPF or Windows Forms, you can also just pass the raw HWND of the window to `SetWindowThemeRaw(IntPtr, Theme)`.
263
244
264
-
<aid="taskbar-theme"></a>
265
245
### Taskbar theme
266
246
267
247
Windows introduced a preference to choose a dark or light taskbar in Windows 10 version 1903. This is controlled by Settings › Personalization › Colors › Choose your default Windows mode.
268
248
269
249
DarkNet exposes the value of this preference with the **`UserTaskbarThemeIsDark`** property, as well as the change event **`UserTaskbarThemeIsDarkChanged`**. You can use these to render a tray icon in the notification area that matches the taskbar's theme, and re-render it when the user preference changes.
270
250
271
-
<aid="demos"></a>
272
251
## Demos
273
252
274
253
You can download the following precompiled demos, or clone this repository and build the demo projects yourself using Visual Studio Community 2022.
275
254
276
-
<aid="wpf-1"></a>
277
255
### WPF
278
256
279
257
Download and run `darknet-demo-wpf.exe` from the [latest release](https://github.com/Aldaviva/DarkNet/releases).
280
258
281
259
Requires [.NET Desktop Runtime 6 x64](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) or later.
282
260
283
-

261
+

284
262
285
-
<aid="windows-forms-1"></a>
286
263
### Windows Forms
287
264
288
265
Download and run `darknet-demo-winforms.exe` from the [latest release](https://github.com/Aldaviva/DarkNet/releases).
289
266
290
267
Requires [.NET Framework 4.8](https://dotnet.microsoft.com/en-us/download/dotnet-framework) or later.
291
268
292
-

269
+

293
270
294
-
<aid="limitations"></a>
295
271
## Limitations
296
272
- This library only changes the theme of the title bar/window chrome/non-client area, as well as the system context menu (the menu that appears when you right click on the title bar, or left click on the title bar icon, or hit `Alt`+`Space`). It does not change the theme of the client area of your window. It is up to you to make that look different when dark mode is enabled. This is difficult with Windows Forms, [particularly on .NET Core](https://github.com/gitextensions/gitextensions/issues/9191).
297
273
- This library currently does not help you persist a user's choice for the mode they want your application to use across separate process executions. You can expose an option and persist that yourself, then pass the desired `Theme` value to the methods in this library.
298
274
299
-
<aid="acknowledgements"></a>
300
275
## Acknowledgements
301
276
302
277
-[Milan Burda](https://github.com/miniak) for explaining how to add this in Electron ([electron/electron #23479: [Windows] Title bar does not respect dark mode](https://github.com/electron/electron/issues/23479))
0 commit comments