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

XAML Compile Causes Failure at Run Time #22110

Open
david-maw opened this issue Apr 29, 2024 · 1 comment
Open

XAML Compile Causes Failure at Run Time #22110

david-maw opened this issue Apr 29, 2024 · 1 comment
Labels
area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@david-maw
Copy link

Description

The symptom was that some code stopped working but only in a Release build. The problem was obscured by DataTempltes, SwipeViews and general cruft, but it came down to XAML like this:

ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:XamlCompile_Binding"
             BindingContext="{local:MainViewModel}"
             x:DataType="local:MainViewModel"
             x:Class="XamlCompile_Binding.MainPage">

    <CollectionView ItemsSource="{Binding Path=People}">
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <VerticalStackLayout>
                    <Button Text="Press Me" HorizontalOptions="Start"
                    Command="{Binding Source={RelativeSource AncestorType={x:Type local:MainViewModel}}, Path= DoSomething}" 
                    CommandParameter="{Binding}"/>
                </VerticalStackLayout>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</ContentPage>

The symptom is that in a Release build the CommandParameter is null whereas in a Debug build the current Person object is passed.

I'm not convinced this is a bug at all, but if not it certainly can make for a surprising feature.

Steps to Reproduce

  1. Load up the project
  2. Build and run a Debug Build
  3. Click on a button, it will display a person's name.
  4. Build and run a Release build.
  5. Click on a button, it will display a message saying the command parameter was null.

Link to public reproduction project repository

https://github.com/david-maw/XamlCompile-Binding.git

Version with bug

8.0.10 SR3

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Windows 11, Android 14

Did you find any workaround?

Yes specifying the correct x:DataType for the DataTemplate (local:Person in this example).

Relevant log output

No response

@david-maw david-maw added the t/bug Something isn't working label Apr 29, 2024
@RoiChen001 RoiChen001 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 29, 2024
@RoiChen001
Copy link

Can repro this issue at Windows platform on the latest 17.10 Preview 5(8.0.7&8.0.21).
22110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants