Skip to content

Add x: directive Nullable #21023

@gerhard17

Description

@gerhard17

Is your feature request related to a problem? Please describe.

Regarding to the documentation https://docs.avaloniaui.net/docs/xaml/directives, please add a x:Nullable 'primitve type element' to Avalonia,

For example, if you want to add a generic type argument Nullable<int>, then currently it can only be done via xmlns:sys="using:System" and x:TypeArguments="sys:Nullable(x:Int32)".

This works, and even I was able to add it globaly to the Avalonia standard namespace https://github.com/avaloniaui, which allows x:TypeArguments="Nullable(x:Int32)"...

...it would be more logical to use the feature as a standard feature with x:TypeArguments="x:Nullable(x:Int32)", if Avalonia treats a Nullable value type as a standard 'primitive type element'.

I was not able to add this with the XmlnsDefinitionAttribute for the x: namespace http://schemas.microsoft.com/winfx/2006/xaml. This would make intellisense happy, but results in compile time errors like:

Internal compiler error: Value does not fall within the expected range. (TypeReferenceResolver) Line 164, position 7.

Unable to resolve suitable regular or attached property DataType on type :.{Unknown type} Line 164, position 7.

Internal compiler error: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index (ResolveContentPropertyTransformer) Line 164, position 7.`

Describe the solution you'd like

`x:TypeArguments="x:Nullable(x:Int32)" and other nullable value types work out of the box with x: prefix

Describe alternatives you've considered

As described above:

xmlns:sys="using:System"andx:TypeArguments="sys:Nullable(x:Int32)"`.

Additional context

Avalonia 11.3.10

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions