WPF in .NET 9.0: Hyphen-based Ligatures
In the last blog posts about WPF in .NET 9.0, you learned about Windows 11 Theming and about the Accent Color. In this blog post, let’s look at a smaller feature called hyphen-based ligatures.
What are Ligatures?
Ligatures are special character cominations used to create a single symbol. For example the characters “->” could be used to create an arrow symbol like this: ➡.
Which ligatures are supported depends on the font that you’re using. Microsoft’s Cascadia Code font supports a lot of ligatures.
If you’ve never heard about Cascadia Code: It’s a monospaced font. Monospaced means that all characters have the same width, which is great for programming. Cascadia Code comes as a system font pre-installed with Windows 11. It’s used for example by the Windows Terminal.
The ligatures supported by Cascadia Code can be found in the GitHub repo of the font. They look like below.
As you can see, there are some ligatures that use hyphens. These are supported by WPF’s TextBlock
since .NET 9.0. Let’s take a look at an example.
Cascadia Code va. Cascadia Mono
If you’re a developer using Visual Studio, you might have checked your font under Tools->Options. Depending on your chosen option, you might see there that the editor font is set to Cascadia Mono. Cascadia Mono is the exact same font as Cascadia Code, but it has no support for ligatures. If you want to use ligatures in your code editor in Visual Studio, you can switch the font from Cascadia Mono to Cascadia Code.
Hyphen-based Ligatures in WPF
In WPF, the ligatures with hyphens were not supported before .NET 9.0. To try the feature, let’s create a new WPF project and put this TextBlock
into the Grid
in the MainWindow.xaml file:
<TextBlock FontFamily="Cascadia Code">
Hyphen-based ligatures in WPF: --> <--
</TextBlock>
The XML entity references >
(greater than) and <
(less than) are used to define the characters >
and <
. So, here the characters -->
and <--
are defined.
Before .NET 9.0, the TextBlock
has the following output. As you can see, the hyphen-based ligatures are not supported.

With .NET 9.0 or later, the same TextBlock
looks like below. As you can see, the characters -->
and <--
are combined into the arrow symbols of the Cascadia Code font.

If you want to play a bit with ligatures, you can also use a TextBox
instead of a TextBlock
. Just put the following TextBox
with the Cascadia Code font into your WPF app and then you can start typing and seeing the results live:
<TextBox FontFamily="Cascadia Code"/>
Let’s run the app in .NET 8.0 and type some text into the TextBox
. This time I use these characters: <!--
. The output looks like below with .NET 8.0.

In .NET 9.0 or later, the same text in the same TextBox
leads to the expected symbol of the Cascadia Code font that you see in the screenshot below.

Summary
If you build an application, where a font with ligatures like Cascadia Code is used, then the support for hyphen-based ligatures can be a big deal for you. It’s a simple, but powerful new feature of WPF in .NET 9.0.
Thanks for reading,
Thomas
Leave a Reply