Skip to content

Commit 2c9ea06

Browse files
committed
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.
1 parent 4c40f30 commit 2c9ea06

File tree

3 files changed

+11
-36
lines changed

3 files changed

+11
-36
lines changed

.github/images/demo-winforms.png

-12.8 KB
Loading

.github/images/demo-wpf.png

-19.6 KB
Loading

Readme.md

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
Enable native Windows dark mode for your WPF and Windows Forms title bars.
77

8-
![WPF window with dark title bar](.github/images/demo-wpf.png)
8+
<!-- Absolute URL so the URL resolves when viewed not on GitHub, for example, on NuGet Gallery -->
9+
![WPF window with dark title bar](https://raw.githubusercontent.com/Aldaviva/DarkNet/master/.github/images/demo-wpf.png)
910

10-
<!-- MarkdownTOC autolink="true" bracket="round" autoanchor="true" levels="1,2,3,4" -->
11+
<!-- MarkdownTOC autolink="true" bracket="round" autoanchor="false" levels="1,2,3,4" -->
1112

1213
- [Requirements](#requirements)
1314
- [Installation](#installation)
@@ -26,7 +27,7 @@ Enable native Windows dark mode for your WPF and Windows Forms title bars.
2627
- [Before showing a new window](#before-showing-a-new-window-1)
2728
- [After showing a window](#after-showing-a-window-1)
2829
- [Complete example](#complete-example-1)
29-
- [Raw HWND](#raw-hwnd)
30+
- [HWND](#hwnd)
3031
- [Taskbar theme](#taskbar-theme)
3132
- [Demos](#demos)
3233
- [WPF](#wpf-1)
@@ -36,7 +37,6 @@ Enable native Windows dark mode for your WPF and Windows Forms title bars.
3637

3738
<!-- /MarkdownTOC -->
3839

39-
<a id="requirements"></a>
4040
## Requirements
4141

4242
- .NET runtime
@@ -49,7 +49,6 @@ Enable native Windows dark mode for your WPF and Windows Forms title bars.
4949
- You can still run your program on earlier Windows versions as well, but the title bar won't turn dark
5050
- Windows Presentation Foundation, Windows Forms, or access to the native window handle of other windows in your process
5151

52-
<a id="installation"></a>
5352
## Installation
5453

5554
[DarkNet is available in NuGet Gallery.](https://www.nuget.org/packages/DarkNet/)
@@ -61,18 +60,14 @@ dotnet add package DarkNet
6160
Install-Package DarkNet
6261
```
6362

64-
<a id="usage"></a>
6563
## Usage
6664

67-
<a id="basics"></a>
6865
### Basics
6966

70-
<a id="entry-point"></a>
7167
#### Entry point
7268

7369
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()`.
7470

75-
<a id="methods"></a>
7671
#### Methods
7772

7873
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
8176

8277
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.
8378
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:
84-
|Window type|Method signature|
85-
|-|-|
86-
|WPF|`SetWindowThemeWpf(Window, Theme)`|
87-
|Windows Forms|`SetWindowThemeForms(Form, Theme)`|
88-
|Raw HWND|`SetWindowThemeRaw(IntPtr, Theme)`|
79+
- **WPF:** `SetWindowThemeWpf(Window, Theme)`
80+
- **Forms:** `SetWindowThemeForms(Form, Theme)`
81+
- **HWND:** `SetWindowThemeRaw(IntPtr, Theme)`
8982

9083
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.
9184

9285
*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.*
9386

94-
<a id="themes"></a>
9587
#### Themes
9688

9789
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
108100

109101
Try the [demo apps](#demos) to see this behavior in action.
110102

111-
<a id="wpf"></a>
112103
### WPF
113104

114-
<a id="on-application-startup"></a>
115105
#### On application startup
116106

117107
Before showing **any** windows in your application, you may optionally call
@@ -136,7 +126,6 @@ public partial class App: Application {
136126
}
137127
```
138128

139-
<a id="before-showing-a-new-window"></a>
140129
#### Before showing a new window
141130

142131
Before showing **each** window in your application, you have to set the theme for that window.
@@ -165,22 +154,18 @@ public partial class MainWindow {
165154

166155
You must perform this step for **every** window you show in your application, not just the first one.
167156

168-
<a id="after-showing-a-window"></a>
169157
#### After showing a window
170158

171159
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.
172160

173161
Try the [demo apps](#demos) to see this behavior in action.
174162

175-
<a id="complete-example"></a>
176163
#### Complete example
177164

178165
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).
179166

180-
<a id="windows-forms"></a>
181167
### Windows Forms
182168

183-
<a id="on-application-startup-1"></a>
184169
#### On application startup
185170

186171
Before showing **any** windows in your application, you may optionally call
@@ -205,7 +190,6 @@ internal static class Program {
205190
}
206191
```
207192

208-
<a id="before-showing-a-new-window-1"></a>
209193
#### Before showing a new window
210194

211195
Before showing **each** window in your application, you have to set the theme for that window.
@@ -223,14 +207,12 @@ DarkNet.Instance.SetWindowThemeForms(mainForm, Theme.Auto);
223207

224208
You must perform this step for **every** window you show in your application, not just the first one.
225209

226-
<a id="after-showing-a-window-1"></a>
227210
#### After showing a window
228211

229212
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.
230213

231214
Try the [demo apps](#demos) to see this behavior in action.
232215

233-
<a id="complete-example-1"></a>
234216
#### Complete example
235217

236218
```cs
@@ -256,47 +238,40 @@ internal static class Program {
256238

257239
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).
258240

259-
<a id="raw-hwnd"></a>
260-
### Raw HWND
241+
### HWND
261242

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)`.
263244

264-
<a id="taskbar-theme"></a>
265245
### Taskbar theme
266246

267247
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.
268248

269249
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.
270250

271-
<a id="demos"></a>
272251
## Demos
273252

274253
You can download the following precompiled demos, or clone this repository and build the demo projects yourself using Visual Studio Community 2022.
275254

276-
<a id="wpf-1"></a>
277255
### WPF
278256

279257
Download and run `darknet-demo-wpf.exe` from the [latest release](https://github.com/Aldaviva/DarkNet/releases).
280258

281259
Requires [.NET Desktop Runtime 6 x64](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) or later.
282260

283-
![WPF window with dark title bar](.github/images/demo-wpf.png)
261+
![WPF window with dark title bar](https://raw.githubusercontent.com/Aldaviva/DarkNet/master/.github/images/demo-wpf.png)
284262

285-
<a id="windows-forms-1"></a>
286263
### Windows Forms
287264

288265
Download and run `darknet-demo-winforms.exe` from the [latest release](https://github.com/Aldaviva/DarkNet/releases).
289266

290267
Requires [.NET Framework 4.8](https://dotnet.microsoft.com/en-us/download/dotnet-framework) or later.
291268

292-
![Windows Forms window with dark title bar](.github/images/demo-winforms.png)
269+
![Windows Forms window with dark title bar](https://raw.githubusercontent.com/Aldaviva/DarkNet/master/.github/images/demo-winforms.png)
293270

294-
<a id="limitations"></a>
295271
## Limitations
296272
- 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).
297273
- 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.
298274

299-
<a id="acknowledgements"></a>
300275
## Acknowledgements
301276

302277
- [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

Comments
 (0)