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 error is shown when the content of a DataTemplate is not a View #22485

Closed
marchev-prgs opened this issue May 17, 2024 · 9 comments
Closed
Labels
area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@marchev-prgs
Copy link

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 -

public object CreateContent()
).

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 marchev-prgs added the t/bug Something isn't working label May 17, 2024
Copy link
Contributor

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.

@jsuarezruiz jsuarezruiz added area-xaml XAML, CSS, Triggers, Behaviors partner Issue or Request from a partner team labels May 17, 2024
@ninachen03 ninachen03 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels May 17, 2024
@ninachen03
Copy link

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

@PureWeen PureWeen added this to the .NET 9 Planning milestone May 17, 2024
@PureWeen PureWeen added area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging and removed area-xaml XAML, CSS, Triggers, Behaviors labels May 17, 2024
@PureWeen
Copy link
Member

@mgoertz-msft @StephaneDelcroix thoughts?

@mgoertz-msft
Copy link
Contributor

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

@marchev-prgs
Copy link
Author

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.

@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 10, 2024
@mgoertz-msft
Copy link
Contributor

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

@jstedfast
Copy link
Member

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

@mariusmcalpine
Copy link

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

@mgoertz-msft
Copy link
Contributor

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

@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-tooling XAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debugging partner Issue or Request from a partner team platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst 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

8 participants