Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ItemsPanelTemplate doesn't support AoT-safe binding #10070

Open
Arlodotexe opened this issue Oct 15, 2024 · 0 comments
Open

ItemsPanelTemplate doesn't support AoT-safe binding #10070

Arlodotexe opened this issue Oct 15, 2024 · 0 comments
Labels
needs-triage Issue needs to be triaged by the area owners

Comments

@Arlodotexe
Copy link

We are encountering issues when trying to bind properties within an ItemsPanelTemplate. Currently, we have this code in our project:

        <GridView Name="GridView"
                  ItemTemplate="{StaticResource StaggeredTemplate}"
                  ItemsSource="{x:Bind ColorsCollection, Mode=OneWay}">

            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <controls:StaggeredPanel ColumnSpacing="{Binding ColumnSpacing, ElementName=ThisSamplePage, Mode=OneWay}"
                                             DesiredColumnWidth="{Binding DesiredColumnWidth, ElementName=ThisSamplePage, Mode=OneWay}"
                                             RowSpacing="{Binding RowSpacing, ElementName=ThisSamplePage, Mode=OneWay}" />
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
        </GridView>

This will crash at runtime when compiled under NativeAoT for both the WindowsAppSDK and UWP with modern .NET.

Removing the binding on the ItemsPanelTemplate fixes the issue, as shown in the image below:
Image

Unfortunately, we cannot use x:Bind here because it results in the following error:

1>StaggeredPanelSample.xaml(42,22): XamlCompiler error WMC1111: DataTemplates containing x:Bind need a DataType to be specified using 'x:DataType'
1>Done building project \"Primitives.Samples.csproj\" -- FAILED.

Neither a DataTemplate nor its accompanying x:DataType can be added here since ItemsPanelTemplate is already a template and must have a first child of type Panel.

Looking through documentation for 'official' examples of binding properties on an ItemsPanelTemplate, I'm not finding any where these properties are bound, whether using {Binding}, {x:Bind}, or {TemplateBinding}.

Using {Binding} worked before, but it's not AoT safe and x:Bind doesn't seem to be compatible. What is the platform recommended approach here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

1 participant