Page 1 of 1

Textblock comboitem not displaying when selected

Posted: 24 Oct 2020, 20:33
by mdube
Hi,

I ran into this issue. The following will display both options when combo box is opened, but selecting Option 1 will lead to an invisible selected item.
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  <ComboBox Foreground="red" Height="36" SelectedIndex="1">
    <ComboBoxItem>
      <TextBlock Foreground="green">Option 1</TextBlock>
    </ComboBoxItem>
    <ComboBoxItem Foreground="blue">Option 2</ComboBoxItem>
  </ComboBox>
</Grid>
Regards

Re: Textblock comboitem not displaying when selected

Posted: 26 Oct 2020, 10:25
by sfernandez
Hi mdube,

This is a known issue that is not yet fixed: #1125.

The workaround could be to move the item visual tree to the ContentTemplate like this:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <ComboBox Foreground="red" Height="36" SelectedIndex="1">
    <ComboBoxItem Content="Option 1">
      <ComboBoxItem.ContentTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding}" Foreground="green"/>
        </DataTemplate>
      </ComboBoxItem.ContentTemplate>
    </ComboBoxItem>
    <ComboBoxItem Foreground="blue">Option 2</ComboBoxItem>
  </ComboBox>
</Grid>
Would that work for you?

Re: Textblock comboitem not displaying when selected

Posted: 28 Oct 2020, 20:05
by mdube
Yes, this is a fine workaround. Thanks.