Open sudharsan-narayanan opened 1 year ago
You are using x:Bind
in a wrong way. Your data template does not have x:DataType
.
Also, your custom control uses contentpresenter without having content (it will always be null
), and x:Bind mechanism does not work with null DataContexts.
This is not a bug in winui.
In ComboBox ItemTemplate, we can't be able to use x:bind to bind the property's value for below code,
`<ComboBox x:Name="CountryComboBox"
ItemsSource="{x:Bind model.Countries}" >
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="local:Country">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ImageIcon
Grid.Column="0"
Width="24"
Height="24"
Source="{x:Bind CountryFlagPath}" />
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
Text="{x:Bind CountryName}" />
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>`
This is probably related also to #2508
Describe the bug
When we use the ComboBox ItemsSource as x:bind inside the Data Template, it uses as custom control. The binding item source value is not rendering in the Combobox items. Please find the sample and video below for more details,
App15.zip
https://github.com/microsoft/microsoft-ui-xaml/assets/93642597/d746805e-960a-4d1d-a08c-6d9deee76092
In x:bind, it not works. (ItemsSource="{x:Bind local:MainViewModel.ComboBoxItems, Mode=OneWay}")
In Binding, it works. (ItemsSource="{Binding ComboBoxItems}")
Steps to reproduce the bug
Expected behavior
Need to show the items in both x:bind and Binding
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.3.1: 1.3.230502000
Windows version
Windows 11 (21H2): Build 22000
Additional context
No response