Skip to content
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 .NET 9 what's new #1921

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions dotnet-desktop-guide/net/wpf/whats-new/index.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
---
title: What's new in Windows Presentation Foundation
description: Learn about what's new in Windows Presentation Foundation (WPF). This article covers changes to WPF since .NET 7 was released.
ms.date: 10/24/2024
ms.date: 11/07/2024
ms.topic: conceptual
---

# What's new in Windows Presentation Foundation

Each .NET release introduces a new version of Windows Presentation Foundation (WPF). This article teaches you what's new in each release.

## .NET 9

Enhanced support for building modern apps with WPF with several theming enhancements:

- [Overview of WPF on .NET 9](net90.md)
- [ThemeMode API](net90.md#thememode-api)
- [AccentColors as SystemColors](net90.md#accentcolors-as-systemcolors)
- [Hyphen based ligature support](net90.md#hyphen-based-ligature-support)

## .NET 8

WPF added hardware acceleration for remote desktop apps, and a new control for browsing and selecting folders in .NET 8.

- [Overview of WPF on .NET 8](net80.md).
- [Overview of WPF on .NET 8](net80.md)
- [Hardware acceleration on RDP applications](net80.md#hardware-acceleration)
- [OpenFolderDialog](net80.md#openfolderdialog)

## .NET 7

WPF added some key performance improvements in .NET 7.

- [Overview of WPF on .NET 7](net70.md).
- [Overview of WPF on .NET 7](net70.md)
- [Performance improvements](net70.md#performance-improvements)
- [Accessibility improvements and fixes](net70.md#accessibility-improvements-and-fixes)
- [Bug fixes](net70.md#bug-fixes)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
175 changes: 175 additions & 0 deletions dotnet-desktop-guide/net/wpf/whats-new/net90.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
---
title: What's new in WPF for .NET 9
description: Learn about what's new in Windows Presentation Foundation (WPF) for .NET 9. .NET 9 was released November 2024.
ms.date: 11/07/2024
ms.topic: conceptual
---

# What's new for .NET 9 (WPF .NET)

As part of the ongoing modernization of Windows Presentation Foundation (WPF), applications built on WPF and running on Windows 10 or later can now take advantage of cutting-edge design elements and behaviors. Key enhancements include:

- Support for light and dark themes
- Rounded corners for controls
- Compliance with Windows 11 design guidelines
- Accent color support for controls

The introduction of the new Fluent theme delivers a fresh, modern Windows 11 aesthetic to WPF applications. With integrated Light/Dark mode and system accent color support, this update is set to enhance user engagement by giving WPF applications a contemporary, polished appearance.

First showcased at Build 2024, the Fluent theme is now generally available as part of the official .NET 9 release for Windows 10, Windows 11, and also Windows Server 2019.

WPF Gallery App is a sample tool that demonstrates WPF controls and styles to a WPF application in .NET 9 and onwards. The source code for this app is available on [GitHub](https://github.com/microsoft/WPF-Samples).

![WPF gallery app showcased in light mode](./media/wpflight.png)

![WPF gallery app showcased in dark mode](./media/wpfdark.png)

## ThemeMode API

This experimental API enables easy switching between Fluent Themes in WPF applications, improving user experience and accessibility. This experimental API, available at both the Application and Window level, allows developers to dynamically toggle between Light, Dark, System, or None (Default) themes, offering greater flexibility in adapting app visuals.

### Setting Application ThemeMode from XAML

In App.xaml include the ThemeMode property as shown below.

```xml
<Application
x:Class="YourSampleApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:YourSampleApplication"
ThemeMode="Dark">
<Application.Resources>

</Application.Resources>
</Application>
```

### Setting Window ThemeMode from XAML

Similar to Application ThemeMode, set the ThemeMode at the desired window's xaml as shown below.

```xml
<Window
x:Class="YourSampleApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:YourSampleApplication"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" ThemeMode="Dark">
<Grid>

</Grid>
</Window>
```

### Setting ThemeMode from Code-Behind

Since the API is experimental, the usage of ThemeMode from code-behind is a bit restricted. To use ThemeMode from code-behind, the developer either needs to configurethe project to ignore the WPF0001 warning for the project or suppress the warning where needed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configurethe --> configure the


**To configure the Project to ignore the warning:** In your project's .csproj, set the following tag:

```xml
<PropertyGroup>
<NoWarn>WPF0001<NoWarn>
</PropertyGroup>
```

Use the property from code-behind:

```cs
Application.Current.ThemeMode = ThemeMode.Light;
```

or, to apply it to the current window

```cs
this.ThemeMode = ThemeMode.Light;
```

**To suppress the warning:** Disable and enable the pragma warning as shown below

```cs
#pragma warning disable WPF0001
Application.Current.ThemeMode = ThemeMode.Light;
#pragma warning restore WPF0001
```

### Expected behavior of the API

1. When the `ThemeMode` is set to Light or Dark or System, the Fluent Themes are applied to the respective Application or Window.
2. The `ThemeMode` when set to System respects the current operating system's theme settings. This involves detecting whether the user is utilizing a light or dark theme as their App Mode.
3. When the `ThemeMode` is set to None, the Fluent Themes are not applied and the default `Aero2` theme is used.
4. Accent color changes will be adhered to whenever the Fluent Theme is applied irrespective of `ThemeMode`.
5. When the `ThemeMode` is set to a Window, it will take precedence over the Application's `ThemeMode`. In case Window `ThemeMode` is set to None, the window will adhere to Application's `ThemeMode`, even if Application uses Fluent Theme.
6. The default value of `ThemeMod`e is None.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ThemeMode --> ThemeMode


In addition to these behaviors, the ThemeMode is also designed to respect the Fluent Theme Dictionary added to the Application or Window. AFluent Themes can also be loaded by including the respective Fluent Dictionary. If the given application or window is loaded with a given Fluent Dictionary, let's say Light, then the ThemeMode will be synced to Light Mode as well and vice-versa.

This can be enabled by adding the following to your App.xaml:

```xml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
```

## AccentColors as SystemColors

Since Windows 10, Accent Color became a cornerstone for visual styling, enhancing consistency across apps by aligning with the system theme. The latest introduction of AccentColors and corresponding brushes in SystemColors simplifies this process for WPF developers, offering them direct access to system accent colors and their variations.

This streamlines the workflow, ensuring apps can seamlessly integrate system-defined aesthetics, ultimately improving the user experience without extra coding overhead. The new API offers a more reliable and efficient way to deliver visually cohesive applications.

1. **Colors**: The following System.Windows.Media.Color are being introduced corresponding to the current accent color of the system and its primary, secondary and tertiary variations in both Light and Dark mode.

```cs
AccentColor
AccentColorLight1
AccentColorLight2
AccentColorLight3
AccentColorDark1
AccentColorDark2
AccentColorDark3
```

2. **ResourceKey**: Similary, the following System.Windows.ResourceKey are being introduced.

```cs
AccentColorKey
AccentColorLight1Key
AccentColorLight2Key
AccentColorLight3Key
AccentColorDark1Key
AccentColorDark2Key
AccentColorDark3Key
```

3. **SolidColorBrush**: Similary, the following System.Windows.Media.SolidColorBrush are being introduced.

```cs
AccentColorBrush
AccentColorLight1Brush
AccentColorLight2Brush
AccentColorLight3Brush
AccentColorDark1Brush
AccentColorDark2Brush
AccentColorDark3Brush
```

### Usage of the `AccentColor` APIs

Usage of the AccentColor APIs, update the applicable properties as below:

```xml
<Button Content="Sample WPF Button" Background="{x:Static SystemColors.AccentColorBrush}" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This usage is not right, it throw's Argument Null exception when the AccentColor is changed in the system. This should be replaced with the following :

<Button Content="Sample WPF Button" Background="{DynamicResource {x:Static SystemColors.AccentColorBrushKey}}" />

```

## Hyphen based ligature support

Based on the WPF community feedback, we have now fixed the issue with Hyphen based ligatures not working in WPF. Summary: A call to LsTxtFmt (Text Formatter) is made when a line is being created. Previously, in LsTxtFmt, glyphing was only performed for regular characters. However, after the fix, glyphing will also be performed for special characters, such as hyphens.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of going into the details like LsTxtFmt, would it be better to provide an image showing the difference ?

Loading