I have a CustomControl that is derived from ComboBox and I would like to show certain items with Bold text, some with Italic and some normal, depending on associated data. Since there's no XAML associated with this, I am having trouble finding a way to handle this. The items are DataBound to the control via the ItemsSource property so each item type is just the Object type for my data object.
Any ideas?
You can use DataTemplate
for your custom ComboBox
with overriding ComboBox's ItemTemplate
<CustomComboBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="tbTitle" Text="{Binding Title}"/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Style}" Value="0">
<Setter TargetName="tbTitle" Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding Style}" Value="1">
<Setter TargetName="tbTitle" Property="Foreground" Value="Red"/>
<Setter TargetName="tbTitle" Property="FontStyle" Value="Italic"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</CustomComboBox.ItemTemplate>
The CustomCombobox
's ItemSource is collection of a simple object with a string property Title
And an int property Style
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With