maui icon indicating copy to clipboard operation
maui copied to clipboard

XAML error is shown when the content of a DataTemplate is not a View

Open marchev-prgs opened this issue 1 year ago • 5 comments

Description

There is an error shown in VS when in XAML the Content of a DataTemplate is not a View:

image

    <DataTemplate x:Key="template1">
        <local:MyTabViewItem>
            <local:MyTabViewItem.Header>
                <Label Text="{Binding MyHeaderText}" />
            </local:MyTabViewItem.Header>
            <local:MyTabViewItem.Content>
                <Grid>
                    <Label Text="{Binding MyContentText}" />
                </Grid>
            </local:MyTabViewItem.Content>
        </local:MyTabViewItem>
    </DataTemplate>

The error says "Property DataTemplateContent does not support value of type MyTabViewItem".

Note that MyTabViewItem is not a View, it is a BindableObject: public class MyTabViewItem : BindableObject { }

Rationale: In our case, we have a custom TabView. Each TabView-item contains two views - one header view, and one content view. This is one of the reasons we chose for the MyTabViewItem to not be a view, and it has two properties that contain the two views - Header and Content properties. While we understand that most items-controls will use the DataTemplate with a View in them, this is not necessarily a restriction, as the DataTemplate can create content of type object (for reference see the signature of the CreateContent() method of the DataTemplate - https://github.com/dotnet/maui/blob/f2cc45e3e95370fb170464b6af141e1cb88172c2/src/Controls/src/Core/ElementTemplate.cs#L73).

This is why we would like for that error to be removed as users of our custom TabView may think there is an error with their code.

Steps to Reproduce

  1. Download the repo from the link (https://github.com/telerik/ms-samples) and go to Maui/XamlErrorForDataTemplate
  2. Open the project
  3. Go to MainPage.xaml

Expected Behavior: No error should be displayed.

Actual Behavior: The whole DataTemplate is underlined and an error is displayed - "Property DataTemplateContent does not support value of type MyTabViewItem".

Link to public reproduction project repository

https://github.com/telerik/ms-samples/tree/main/Maui/XamlErrorForDataTemplate

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

8.0.7 SR2

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

No response

Did you find any workaround?

I did not find a workaround.

Relevant log output

No response

marchev-prgs avatar May 17 '24 11:05 marchev-prgs

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar May 17 '24 11:05 github-actions[bot]

Verified this issue with Visual Studio 17.10 Preview 7 (8.0.40 & 8.0.3). Can repro it. image

ninachen03 avatar May 17 '24 12:05 ninachen03

@mgoertz-msft @StephaneDelcroix thoughts?

PureWeen avatar May 17 '24 14:05 PureWeen

What is the property type of DataTemplate.DataTemplateContent? Is MyTabViewItem assignable to it?

mgoertz-msft avatar May 17 '24 15:05 mgoertz-msft

What is the property type of DataTemplate.DataTemplateContent? Is MyTabViewItem assignable to it?

Yes, it is assignable, the sample runs correctly. It's just the shown error that casts doubt.

The signature of the method in the DataTemplate is object CreateContent() (link). And in my case a tab-item is a BindableObject.

marchev-prgs avatar May 21 '24 12:05 marchev-prgs

Sorry, this was just now brought again to my attention. We don't usually look here for VS tooling bugs. Creating a Developer Community ticket in those cases is a better way to track issues with VS.

I created the following bug for VS for this:

Bug AB#2199135: XAML error is shown when the content of a DataTemplate is not a View

mgoertz-msft avatar Aug 08 '24 22:08 mgoertz-msft

The AzDO bug report was closed as fixed on 8/13 and is slated as part of 17.12.

jstedfast avatar Sep 12 '24 19:09 jstedfast

Good day, When can we expect this fix to be available? Thanks

mariusmcalpine avatar Oct 04 '24 10:10 mariusmcalpine

@mariusmcalpine The fix is available in VS 17.12 Preview 2.0.

mgoertz-msft avatar Oct 04 '24 14:10 mgoertz-msft