I have created a ComboBox
with a custom items template like this:
<ComboBox ItemsSource="{Binding Clases}" SelectedValue="{Binding Clase}" Style="{StaticResource ComboBoxStyle}" Grid.Column="0">
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ComboBox.ItemContainerStyle>
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0 2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<TextBlock Text="{Binding CLASE}" VerticalAlignment="Center"/>
</Grid>
<Button Command="{Binding DataContext.BorrarClaseCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" CommandParameter="{Binding}" ToolTip="BORRAR CLASE" Grid.Column="1">
<materialDesign:PackIcon Kind="Delete"/>
</Button>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
The ComboBox
is binding to the Clase
value in the view model. Clase
is a variable of type CLASE_TYPE
which is a class that looks like this:
public partial class CLASE_TYPE
{
public decimal ID { get; set; }
public string CLASE { get; set; }
}
The result looks like this:
The problem comes when I select a value, the selected value is showing in the ComboBox
like this:
How can I avoid this and only show the value of CLASE
of the CLASE_TYPE
class?