Asam
Asam

Reputation: 1

WinUI 3 with .NET 9 and AOT: Event-to-Command in XAML not working

I'm experiencing an issue with WinUI 3 and .NET 9 when publishing with AOT. In my XAML, I use an event-to-command behavior to bind an event to a command in my ViewModel. This works perfectly in Debug and Release builds, but once I publish with AOT, the behavior stops working—the command is not invoked when the event occurs.

<Page
    x:Class="View_Tool.Views.ScenarioSelectionPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:local="using:View_Tool.ViewModels"
    xmlns:converters="using:View_Tool.Helpers"
    NavigationCacheMode="Enabled"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Page.Resources>
        <converters:BreadcrumbBarEventArgsConverter x:Key="BreadcrumbBarEventArgsConverter" />
    </Page.Resources>
      <BreadcrumbBar Grid.Row="0" x:Name="BreadcrumbBar" HorizontalAlignment="Left" IsEnabled="True"
                       VerticalAlignment="Stretch" VerticalContentAlignment="Center"
                       ItemsSource="{x:Bind ViewModel.BreadcrumbItems}" Margin="0,10,10,0">
            <interactivity:Interaction.Behaviors>
                <interactivity:EventTriggerBehavior EventName="ItemClicked" SourceObject="{x:Bind BreadcrumbBar}">
                    <interactivity:InvokeCommandAction Command="{x:Bind ViewModel.BreadcrumbBarItemSelectedCommand}"
                                                       InputConverter="{StaticResource BreadcrumbBarEventArgsConverter}" />
                </interactivity:EventTriggerBehavior>
            </interactivity:Interaction.Behaviors>
            <BreadcrumbBar.ItemTemplate>
                <DataTemplate x:DataType="local:BreadcrumbItem">
                    <BreadcrumbBarItem Foreground="{ThemeResource AccentFillColorSecondaryBrush}"
                                       FontSize="{StaticResource FontSizeM}">
                        <BreadcrumbBarItem.ContentTemplate>
                            <DataTemplate x:DataType="local:BreadcrumbItem">
                                <TextBlock Text="{x:Bind Title}" />
                            </DataTemplate>
                        </BreadcrumbBarItem.ContentTemplate>

                    </BreadcrumbBarItem>
                </DataTemplate>
            </BreadcrumbBar.ItemTemplate>
        </BreadcrumbBar>

Currently, I have a workaround implemented in the code-behind.

private void BreadcrumbBar_OnItemClicked(BreadcrumbBar sender, BreadcrumbBarItemClickedEventArgs args)
 {
     ViewModel.BreadcrumbBarItemSelectedCommand.Execute(args.Index);
 }

Does anyone have any idea how to get it working with AOT and XAML?

Upvotes: 0

Views: 35

Answers (0)

Related Questions