Skip to content

Bug: Wrapping ListViewItemPresenter into Grid within a ControlTemplate throws an exception #6562

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

Closed
1 of 2 tasks
ksmutny opened this issue Jan 8, 2022 · 5 comments
Closed
1 of 2 tasks
Labels
area-Lists ListView, GridView, ListBox, etc no-issue-activity team-Controls Issue for the Controls team

Comments

@ksmutny
Copy link

ksmutny commented Jan 8, 2022

Describe the bug

Trying to customize a presentation of a ListViewItem through customizing a ControlTemplate using ListViewItemPresenter within another container, e.g. Grid or StackPanel. When using generic ContentPresenter, the code works as expected, but with ListViewItemPresenter, it throws an exception.

Steps to reproduce the bug

The following code throws an Unhandled exception at 0x79FF7FD9 (Microsoft.ui.xaml.dll) in test.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x15BCFFB8, 0x00000004).

<ListView>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem" BasedOn="{StaticResource DefaultListViewItemStyle}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <Grid>
                            <ListViewItemPresenter/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ListView.ItemContainerStyle>
    <ListView.Items>
        <TextBlock>Item 1</TextBlock>
        <TextBlock>Item 2</TextBlock>
        <TextBlock>Item 3</TextBlock>
        <TextBlock>Item 4</TextBlock>
        <TextBlock>Item 5</TextBlock>
    </ListView.Items>
</ListView>

Expected behavior

I expect the code to work. When <ListViewItemPresenter/> is replaced with a generic <ContentPresenter/>, no exception is thrown and the code works as expected. (Without all the goodies of ListViewItemPresenter, of course).

Is there any reason why ListViewItemPresenter throws an exception and cannot be used this way, or is it a bug?

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.0 (If you're seeing your issue in older previews of WinUI 3, please try this release)

Windows app type

  • UWP
  • Win32

Device form factor

Desktop

Windows version

Insider Build (xxxxx)

Additional context

Windows 11 Pro version 22000.376

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Jan 8, 2022
@StephenLPeters StephenLPeters added area-Lists ListView, GridView, ListBox, etc team-Controls Issue for the Controls team labels Mar 2, 2022
@StephenLPeters
Copy link
Contributor

I suspect ListViewItemPresenter assumes in code that its parent will be a ListViewItem. What does wrapping the LVIP afford you?

@RBrid could maybe confirm my suspicions.

@StephenLPeters StephenLPeters added needs-author-feedback Asked author to supply more information. and removed needs-triage Issue needs to be triaged by the area owners labels Mar 2, 2022
@ghost ghost added the no-recent-activity label Mar 10, 2022
@ghost
Copy link

ghost commented Mar 10, 2022

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.

@ksmutny
Copy link
Author

ksmutny commented Mar 11, 2022

@StephenLPeters Thank you. I was looking for ways to solve this issue: #6560

What am I loosing from ListViewItemPresenter functionality, if I were to replace it by generic ContentPresenter? I read LVIP implements some ListView related optimizations, but didn't find any specifics.

@ghost ghost added needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. no-recent-activity labels Mar 11, 2022
@ojhad
Copy link
Contributor

ojhad commented Mar 14, 2022

@ksmutny You are not going to be able to put a grid between ListViewItem and ListViewItemPresenter. However you should able to place the grid within the ListViewItemPresenter to achieve the customizations you need.

@ojhad ojhad removed the needs-triage Issue needs to be triaged by the area owners label Mar 14, 2022
@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Lists ListView, GridView, ListBox, etc no-issue-activity team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

3 participants