Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF .Net Core 3.0 mapping language primitive types in Xaml

One of the issues I'm facing while converting WPF application from NET Framework 4.7 to .Net Core 3.0 is a problem with mapping primitive types like Double in XAML. In NET Framework this XAML has worked perfectly:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    >

   <sys:Double x:Key="BaseSize">10</sys:Double>
</ResourceDictionary>

However mscorlib does not exist in .Net Core. How can I map primitive types in XAML in .Net Core 3?

Had tried this: https://docs.microsoft.com/en-us/dotnet/framework/xaml-services/built-in-types-for-common-xaml-language-primitives

But for WPF this does not work as it is stated here:

"In WPF, you can use XAML 2009 features but only for XAML that is not markup-compiled. Markup-compiled XAML for WPF and the BAML form of XAML do not currently support the XAML 2009 keywords and features."

like image 991
VladacusB Avatar asked Oct 24 '19 11:10

VladacusB


People also ask

Does .NET Core 3.1 support WPF?

NET Core 3.1 Support for ASP.NET Core, WinForms, and WPF Controls (v19. 2.5)

Does WPF use XAML?

Most WPF apps consist of both XAML markup and code-behind. Within a project, the XAML is written as a . xaml file, and a CLR language such as Microsoft Visual Basic or C# is used to write a code-behind file.

What language is XAML?

Extensible Application Markup Language (XAML /ˈzæməl/ ( listen)) is a declarative XML-based language that Microsoft developed for initializing structured values and objects. It is available under Microsoft's Open Specification Promise.


1 Answers

You can use the exact same markup when targeting .NET Core 3.0, i.e. xmlns:sys="clr-namespace:System;assembly=mscorlib" does actually work. Any reference to mscorlib is type forwarded to System.Runtime automatically.

Try to build the solution or take a look at this GitHub issue if you don't believe me.

Edit: Starting with .NET Core 3.1, you should replace assembly=mscorlib with assembly=System.Runtime.

like image 104
mm8 Avatar answered Oct 13 '22 06:10

mm8