Skip to content

Port .NET MAUI template changes to DeveloperBalance samples#674

Merged
jfversluis merged 2 commits intomainfrom
copilot/fix-673
Sep 16, 2025
Merged

Port .NET MAUI template changes to DeveloperBalance samples#674
jfversluis merged 2 commits intomainfrom
copilot/fix-673

Conversation

Copy link
Contributor

Copilot AI commented Sep 16, 2025

This PR ports the changes from dotnet/maui#31564 to the DeveloperBalance sample applications in both the 9.0 and 10.0 folders.

Background

The original PR addressed an issue where Runtime XAML and XamlC inflators ignore required fields and properties in DataTemplateSelector classes. While XSG (XAML Source Generator) can handle these in some cases, it fails for complex or long references. The solution replaces compile-time checks (which are ignored) with runtime validation.

Changes Made

Updated ChipDataTemplateSelector.cs in both sample versions:

Before:

public class ChipDataTemplateSelector : DataTemplateSelector
{
    public required DataTemplate SelectedTagTemplate { get; set; }
    public required DataTemplate NormalTagTemplate { get; set; }

    protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
    {
        return (item as Tag)?.IsSelected ?? false ? SelectedTagTemplate : NormalTagTemplate;
    }
}

After:

public class ChipDataTemplateSelector : DataTemplateSelector
{
    public DataTemplate? SelectedTagTemplate { get; set; }
    public DataTemplate? NormalTagTemplate { get; set; }

    protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
    {
        return ((item as Tag)?.IsSelected ?? false ? SelectedTagTemplate : NormalTagTemplate) 
            ?? throw new InvalidOperationException("DataTemplates SelectedTagTemplate and NormalTagTemplate must be set to a non-null value.");
    }
}

Files Modified

  • 9.0/Apps/DeveloperBalance/Pages/Controls/ChipDataTemplateSelector.cs
  • 10.0/Apps/DeveloperBalance/Pages/Controls/ChipDataTemplateSelector.cs

The changes ensure compatibility with XAML runtime inflators by replacing the required keyword with nullable types and adding proper runtime validation.

Fixes #673.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…Selector

Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
Copilot AI changed the title [WIP] Post .NET MAUI template changes to DeveloperBalance sample Port .NET MAUI template changes to DeveloperBalance samples Sep 16, 2025
Copilot AI requested a review from jfversluis September 16, 2025 09:49
@jfversluis jfversluis marked this pull request as ready for review September 16, 2025 09:52
@jfversluis jfversluis merged commit 2919497 into main Sep 16, 2025
3 checks passed
@jfversluis jfversluis deleted the copilot/fix-673 branch September 16, 2025 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port .NET MAUI template changes to DeveloperBalance sample

2 participants