microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.29k stars 675 forks source link

Cannot access to nested class in DataTemplate #7760

Open fabianoriccardi opened 1 year ago

fabianoriccardi commented 1 year ago

Describe the bug

Using WinUI3 (Windows App SDK), I cannot access to nested class in DataTemplate x:DataType. I had already tried to look at old issues, and the most relevant seems #3238, however the + symbol doesn't solve the issue.

I'm not sure where I should open the issue (https://github.com/microsoft/ProjectReunion or here)..

Steps to reproduce the bug

A very minimalistic example: In XAML file:

<Window
    x:Class="App1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <ListView ItemsSource="{x:Bind persons}">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="local:MainWindow.Person">
                    <TextBlock Text="{x:Bind Name}"></TextBlock>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackPanel>
</Window>

while che code-behind is:

namespace App1
{
    public sealed partial class MainWindow : Window
    {
        public class Person
        {
            public string Name;
            public string Surname;
        }

        readonly ObservableCollection<Person> persons = new();

        public MainWindow()
        {
            this.InitializeComponent();
            persons.Add(new Person() { Name = "AAA", Surname = "BBB" });
        }
    }
}

If I move class Person in the global scope (removing it from MainWindow class) and modifying the x:DataType to local:Person, the code compiles.

Expected behavior

This code should compile.

Screenshots

Immagine 2022-09-24 213439

NuGet package version

No response

Windows app type

Device form factor

Desktop

Windows version

Windows 10 (21H2): Build 19044

Additional context

No response

Setsu-BHMT commented 1 year ago

This is true for Win32 as well. Nested types cannot be referenced at all at the moment.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Gabboxl commented 1 year ago

Any update on this?

fabianoriccardi commented 3 weeks ago

Out of curiosity, I have tested this issue and I can confirm it is still here with WASDK v1.5.6.

So, I kindly ask the moderators to reopen it.