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 Binding Warning in .NET 9 for Behaviors and ViewModel with Property Binding in .NET MAUI #27631

Open
Kamalesh-Periyasamy opened this issue Feb 7, 2025 · 3 comments
Labels
area-xaml XAML, CSS, Triggers, Behaviors partner/syncfusion Issues / PR's with Syncfusion collaboration platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@Kamalesh-Periyasamy
Copy link

Kamalesh-Periyasamy commented Feb 7, 2025

Description

After upgrading from .NET 8 to .NET 9, XAML bindings involving behaviors and view model with property bindings in .NET MAUI now trigger warnings. This issue arises when binding properties from both the ViewModel and Behavior within the same control, particularly when behaviors define properties like LayoutColor.

I enabled <MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>

This behavior change significantly impacts large projects where behaviors are used extensively for validation. A workaround or official guidance from the MAUI team would be beneficial to maintain clean and efficient XAML bindings without unnecessary warnings.

BindingWaring.mp4

Steps to Reproduce

  1. Run the attached project file.
  2. You can find XC0045 warnings.

TextInputLayoutSample.zip

Link to public reproduction project repository

No response

Version with bug

9.0.30 SR3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

@Kamalesh-Periyasamy Kamalesh-Periyasamy added the t/bug Something isn't working label Feb 7, 2025
@karthikraja-arumugam karthikraja-arumugam added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Feb 7, 2025
@RoiChen001 RoiChen001 added s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage platform/windows 🪟 labels Feb 7, 2025
@RoiChen001
Copy link

I can repro this issue at Windows platform on the latest 17.13.0 Preview 5(9.0.30 & 9.0.22).
Image

@jsuarezruiz jsuarezruiz added this to the .NET 9 Servicing milestone Feb 7, 2025
@sheiksyedm
Copy link

@Kamalesh-Periyasamy To fix this warning, add x:DataType to your XAML to specify the type of the current BindingContext.

https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/data-binding/compiled-bindings?view=net-maui-9.0.

I have added "x:DataType" to the right place on your code. Please refer it.

<ContentPage.BindingContext>
        <viewModels:AddCartridgeViewModel/>
    </ContentPage.BindingContext>
    
    <VerticalStackLayout x:DataType="behaviors:DoubleEntryGreaterThanZeroValidatorBehavior" BackgroundColor="{Binding Source={x:Reference BulletDiameterBehavior}, Path=LayoutColor}" HeightRequest="100" >

        <Entry x:Name="bulletDiameter" 
                 Text="{Binding x:DataType='viewModels:AddCartridgeViewModel', Path=BulletDiameter}" 
                 Background="{Binding Source={x:Reference BulletDiameterBehavior}, Path=LayoutColor}"
                 Focused="bulletDiameter_Focused" 
                 ReturnType="Next">
            <Entry.Behaviors>
                <behaviors:DoubleEntryGreaterThanZeroValidatorBehavior x:Name="BulletDiameterBehavior"  />
            </Entry.Behaviors>
        </Entry>
        
    </VerticalStackLayout>

@PureWeen PureWeen added the area-xaml XAML, CSS, Triggers, Behaviors label Feb 12, 2025
@sisaacks
Copy link

I am having the same issue, x:DatatType does not appear for the Text Property as @sheiksyedy states.
I have yet to find a way to reference a behavior without getting the XC0045 warnings.
Because the Behavior is not in my ViewModel I get this XC0045 warning.
So I am very confused on how to actually add a behavior and not get the warning

<Entry Text="{Binding MuzzleVelocity}" x:Name="MuzzleVelocityEntry" Keyboard="Numeric" Focused="Entry_Focused" Style="{StaticResource EnabledEntryStyle}" toolKit:SetFocusOnEntryCompletedBehavior.NextElement="{Reference ZeroTempInput}" ReturnType="Next"> <Entry.Behaviors> <behaviors:DoubleEntryGreaterThanZeroValidatorBehavior x:Name="MuzzleVelocityBehavior" /> </Entry.Behaviors> </Entry>

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 partner/syncfusion Issues / PR's with Syncfusion collaboration 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

7 participants