Skip to content

System.Runtime.InteropServices.COMException occurs when both DisplayMemberPath and ItemTemplate are set #11693

Description

Describe the bug

The issue occurs when creating a custom control that inherits from ListView and setting both DisplayMemberPath and ItemTemplate. This combination results in a System.Runtime.InteropServices.COMException. Removing DisplayMemberPath="Name" resolves the issue, and the control works as expected. Could you please confirm whether DisplayMemberPath should not be set when an ItemTemplate is defined? Is this the default behavior, or does it indicate a potential issue?

 <local:CustomAutoComplete DisplayMemberPath="Name"
     ItemsSource="{Binding SocialMedias}">
     <local:CustomAutoComplete.ItemTemplate>
         <DataTemplate>
             <TextBlock Text="{Binding Name}"
                        TextWrapping="Wrap" />
         </DataTemplate>
     </local:CustomAutoComplete.ItemTemplate>
 </local:CustomAutoComplete> 

SimpleApp.zip

Why is this important?

We have a custom control that inherits from ListView. Long strings are added as the item source, and our customer requires these strings to be searchable using the custom control. To achieve this, applied an ItemTemplate that includes TextWrapping="Wrap" in the DataTemplate TextBlock, along with setting DisplayMemberPath="Name". This combination resulted in a System.Runtime.InteropServices.COMException.

Steps to reproduce the bug

  1. Run the sample.
  2. Observe that a System.Runtime.InteropServices.COMException occurs.

Actual behavior

No response

Expected behavior

No response

Screenshots

No response

NuGet package version

Windows App SDK 2.4.0

Windows version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageIssue needs to be triaged by the area owners

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions