Skip to content

Issue when Using in Native AOT #390

Description

@ghost1372

Description:

Use ReadMe sample in a new Blank Project.

        <tv:TableView xmlns:tv="using:WinUI.TableView" x:Name="MyTableView" AutoGenerateColumns="False" ItemsSource="{x:Bind ViewModel.Items}">
            <tv:TableView.Columns>
                <tv:TableViewTextColumn Binding="{Binding Name}" Header="Name" />
                <tv:TableViewNumberColumn Binding="{Binding Price}" Header="Price" />
                <tv:TableViewTemplateColumn Header="Quantity">
                    <tv:TableViewTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Quantity}" />
                        </DataTemplate>
                    </tv:TableViewTemplateColumn.CellTemplate>
                    <tv:TableViewTemplateColumn.EditingTemplate>
                        <DataTemplate>
                            <NumberBox Value="{Binding Quantity, Mode=TwoWay}" />
                        </DataTemplate>
                    </tv:TableViewTemplateColumn.EditingTemplate>
                </tv:TableViewTemplateColumn>
            </tv:TableView.Columns>
        </tv:TableView>
public partial class MainViewModel
{
    public ObservableCollection<Item> Items { get; set; }

    public MainViewModel()
    {
        Items = new ObservableCollection<Item>
        {
            new Item { Name = "Item 1", Price = 10.0, Quantity = 1 },
            new Item { Name = "Item 2", Price = 15.0, Quantity = 2 },
            new Item { Name = "Item 3", Price = 20.0, Quantity = 3 },
            // Add more items here
        };
    }
}

[GeneratedBindableCustomProperty]
public partial class Item : INotifyPropertyChanged
{
    private string _name;
    private double _price;
    private int _quantity;

    public string Name
    {
        get => _name;
        set
        {
            _name = value;
            OnPropertyChanged(nameof(Name));
        }
    }
    public double Price
    {
        get => _price;
        set
        {
            _price = value;
            OnPropertyChanged(nameof(Price));
        }
    }
    public int Quantity
    {
        get => _quantity;
        set
        {
            _quantity = value;
            OnPropertyChanged(nameof(Quantity));
        }
    }

    private void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

Steps to Reproduce:

Add following flags in csproj:

<IsAotCompatible>true</IsAotCompatible>
<WindowsPackageType>None</WindowsPackageType>
<WindowsAppSdkSelfContained>true</WindowsAppSdkSelfContained>
<TrimMode>partial</TrimMode>
 <PublishAot>true</PublishAot>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishTrimmed>True</PublishTrimmed>

if you run app with Visual Studio it is working fine:

Image

but, right click on your project and select Publish, choose x64 and publish it.

Image

now if you run published exe file, you will see this:

Image

Expected behavior:

columns and data should be shown normally

Screenshots:

If applicable, add screenshots to help explain your problem.

Environment:

  • Package Version: 1.4.1
  • WinAppSDK Version: 2.2.0

Contribution:

  • I am willing to submit a PR to fix this issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions