microsoft / microsoft/microsoft-ui-xaml
Can't specify `x:DataType` of DataTemplate in ResourceDictionary
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
I have a templated control that has a property of type `Windows.Foundation.Collections.IObservableVector Items{ get; };` that's bound to a `ListView.ItemsSource` and I can't specify the `x:DataType` in the `DataTemplate`. It gives
```
Themes\Generic.xaml(12,43): XamlCompiler error WMC0612: The XAML Binary Format (XBF) generator reported syntax error '0x09C4' : Property Not Found
```
### Steps to reproduce the bug
1. Create a new C++WinUI3 project
2. Create a new templated control with this idl, write a dummy code-behind
```idl
[bindable]
[default_interface]
runtimeclass MyControl : Microsoft.UI.Xaml.Controls.Control
{
MyControl();
Windows.Foundation.Collections.IObservableVector Items{ get; };
}
```
3. In `Themes/Generc.xaml`, add this style
```xml
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:MyControl">
<ListView ItemsSource="{Binding Items, RelativeSource={RelativeSource Mode=TemplatedParent}}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="x:Int32"/>
</ListView.ItemTemplate>
</ListView>
</ControlTemplate>
</Setter.Value>
</Setter>
```
### Expected behavior
Builds fine
### Screenshots
_No response_
### NuGet package version
WinUI 3 - Windows App SDK 1.7.1: 1.7.250401001
### Windows version
Windows 11 (24H2): Build 26100
### Additional context
[Repro](https://github.com/HO-COOH/WinUI-Bug/tree/main/28-CannotUseInt32AsDataType)
Contributor guide
Research direction
Start with the Themes/Generic.xaml example in the issue and the linked 28-CannotUseInt32AsDataType repro project. Run the C++/WinUI 3 project build with the DataTemplate x:DataType="x:Int32" declaration, then trace the XAML compiler handling of this ResourceDictionary case. Done means the repro builds without WMC0612 and the expected template remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100