maui: XamlC Compilation errors when upgrading to Microsoft.Maui.Controls 8.0.20

Description

Update the Nuget packages and compile the app, various compilation errors are reported for things like this…

<Style x:Key="Separator" TargetType="{x:Type BoxView}">
        <Setter Property="Color" Value="{StaticResource Gray-200}"/>
        <Setter Property="HeightRequest" Value="1"/>
        <Setter Property="Margin" Value="0,6"/>
        <Setter Property="HorizontalOptions" Value="FillAndExpand"/>
    </Style>

Error XFC0040 XamlC: Cannot convert value “Color” to “Microsoft.Maui.Controls.BindableProperty”

Other xaml files get comilation error…

Error XamlC: Input string was not in a correct format. Failure to parse near offset 69. Unexpected closing brace without a corresponding opening brace.

Despite them being perfectly valid Xaml and compiling correctly with 8.0.14

Steps to Reproduce

  1. Update Nuget packages to 8.0.20
  2. Compile app (Android/iOS)

Link to public reproduction project repository

No response

Version with bug

8.0.20 SR4

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

8.0.14 SR3.1

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

No, removing the code presented as errors results in a new error reported in another file that was previously not reported.

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 23 (14 by maintainers)

Most upvoted comments

I can confirm removing {x:Type} resolves the issues in both styles and xaml Content pages.

As of 8.0.40 I’m still getting the problem. 8.0.14 works fine.

@cat0363 thanks for the repro, I opened a bugfix PR: https://github.com/dotnet/maui/pull/23043

@simonrozsival , I found a condition that causes a build error. An error occurs with the TargetType of DataTrigger, but it was a case where the DataTrigger existed inside the DataTemplate.

[MainPage.xaml]

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DataTrigerTest"
             x:Class="DataTrigerTest.MainPage" x:DataType="local:ViewModelMainPage">

    <StackLayout Orientation="Vertical" BindableLayout.ItemsSource="{Binding TestList}" Spacing="5">
        <BindableLayout.ItemTemplate>
            <DataTemplate x:DataType="{x:Type local:ViewModelTest}">
                <Grid BackgroundColor="Blue" HeightRequest="30">
                    <Grid.Triggers>
                        <DataTrigger TargetType="{x:Type Grid}" Binding="{Binding TestValue}" Value="0">
                            <Setter Property="BackgroundColor" Value="Red" />
                        </DataTrigger>
                    </Grid.Triggers>
                </Grid>
            </DataTemplate>
        </BindableLayout.ItemTemplate>
    </StackLayout>

</ContentPage>

By changing the TargetType of the above DataTrigger from {x:Type Grid} to Grid, the build will pass.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DataTrigerTest"
             x:Class="DataTrigerTest.MainPage" x:DataType="local:ViewModelMainPage">

    <StackLayout Orientation="Vertical" BindableLayout.ItemsSource="{Binding TestList}" Spacing="5">
        <BindableLayout.ItemTemplate>
            <DataTemplate x:DataType="{x:Type local:ViewModelTest}">
                <Grid BackgroundColor="Blue" HeightRequest="30">
                    <Grid.Triggers>
                        <DataTrigger TargetType="Grid" Binding="{Binding TestValue}" Value="0">
                            <Setter Property="BackgroundColor" Value="Red" />
                        </DataTrigger>
                    </Grid.Triggers>
                </Grid>
            </DataTemplate>
        </BindableLayout.ItemTemplate>
    </StackLayout>

</ContentPage>

The code for MainPage.xaml.cs is shown below.

[MainPage.xaml.cs]

    public partial class MainPage : ContentPage
    {
        private ViewModelMainPage pVmTest = new ViewModelMainPage();

        public MainPage()        
        {
            InitializeComponent();
            this.BindingContext = pVmTest;
        }
    }

    public class ViewModelMainPage
    {
        public List<ViewModelTest> TestList { get; set; }

        public ViewModelMainPage()
        {
            TestList = new List<ViewModelTest>()
            {
                new ViewModelTest() { TestValue = 0 },
                new ViewModelTest() { TestValue = 1 },
                new ViewModelTest() { TestValue = 2 },
                new ViewModelTest() { TestValue = 3 }
            };
        }
    }

    public class ViewModelTest
    {
        public int TestValue { get; set; }
    }

When I investigated the location where the build error occurred, I found that it was when there was a DataTrigger in the DataTemplate as shown above.

@cat0363 I’m only getting MainPage.xaml(36,18): XamlC error XFC0009: No property, BindableProperty, or event found for "Children", or mismatching type between value and property. which is caused by missing <Grid.DataTriggers>, this fixed snippet works correctly:

<Grid IsVisible="True">
    <Grid.Triggers>
        <DataTrigger TargetType="{x:Type Grid}" Binding="{Binding TestValue}" Value="1">
            <Setter Property="IsVisible" Value="False"/>
        </DataTrigger>
    </Grid.Triggers>
</Grid>

I take it back! The workaround does work. I had multiple DataTemplates on the same page.

Updated code:

<ContentPage.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="myTemplate" x:DataType="myNamespace:someModel">