dotnet / dotnet/maui

Suggest to introduce a new attribute, like XamlAlias, so that long type names can be referenced with its Alias

Open
#4,581 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area-xaml proposal/open t/enhancement ☀️
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 14h
Merged PRs (30d)
296

Description

Description

Suggesting to introduce a new attribute, like XamlAlias, so that long view names can be referenced with its Alias.

For example, HorizontalStackLayout can be shortened to HStack and used within the XAML code.

The attributes need to be defined on the definition of intended types. This is similar to the ContentProperty attribute, where mentioning the default content node is optional like ContentPage.Content.

Though it is possible to sub-class the type with the shortened name and use it, the issue will be the style definitions needs to be allowed to extend for derived classes and that can have consequences if other real definitions are available within the project.

During Xaml compilation, the alias names are to be replaced with actual type names.

This will simplify things and improve productivity.

Public API Changes
public class XamlAliasAttribute : Attribute
{
    public string AliasName { get; set; }
}
[XamlAlias("HStack")]
public class HorizontalStackLayout : StackBase
{
    // ...
}
Intended Use-Case

Before:

<HorizontalStackLayout>
<!-- Content -->
</HorizontalStackLayout>

After:

<HStack>
<!-- Content -->
</HStack>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing ContentProperty attribute behavior and the XAML compilation path mentioned in the issue. Determine how aliases would be declared on types, resolved in XAML, and handled in style definitions; the work is done when the proposed HStack syntax resolves to HorizontalStackLayout without breaking existing type or style resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.