microsoft / microsoft/microsoft-ui-xaml
System.Runtime.InteropServices.COMException occurs when both DisplayMemberPath and ItemTemplate are set
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
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?
```
```
[SimpleApp.zip](https://github.com/user-attachments/files/31554392/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_
Contributor guide
Research direction
Start by running the attached SimpleApp.zip sample with Windows App SDK 2.4.0 and reproduce the COMException using the shown ListView markup. Compare the behavior with DisplayMemberPath="Name" removed, then determine whether the combination with ItemTemplate is supported. Done means the behavior is explained and a focused fix or confirmed limitation is documented.
Written by the indexing model from the issue text.
Assessment
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 40/100