Reputation: 377
I have a user control defines in my Application.Resources
and want to use it as a DataTemplate for a ComboBox.
The user control:
<TextBlock
x:Key="ListItemView"
Text="{Binding Name}"
ToolTip="{Binding ToolTip}"/>
The Combox Box in my Window:
<ComboBox
ItemsSource="{Binding ComboBoxItems}"
SelectedItem="{Binding SelectedComboBoxItem}">
<ComboBox.ItemTemplate>
<DataTemplate>
<!-- TODO how to use StaticResource ListItemView in here? -->
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Upvotes: 0
Views: 1051
Reputation: 44
You must put your user control into DataTemplate
<DataTemplate x:Key="ListItemView">
<TextBlock Text="{Binding Name}"
ToolTip="{Binding ToolTip}"/>
</DataTemplate>
Use your data template
<ComboBox ItemsSource="{Binding ComboBoxItems}"
SelectedItem="{Binding SelectedComboBoxItem}"
ItemTemplate="{StaticResource ListItemView}">
</ComboBox>
Upvotes: 2