mdube
Topic Author
Posts: 19
Joined: 23 Aug 2019, 12:14

Textblock comboitem not displaying when selected

24 Oct 2020, 20:33

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
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Textblock comboitem not displaying when selected

26 Oct 2020, 10:25

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?
 
mdube
Topic Author
Posts: 19
Joined: 23 Aug 2019, 12:14

Re: Textblock comboitem not displaying when selected

28 Oct 2020, 20:05

Yes, this is a fine workaround. Thanks.

Who is online

Users browsing this forum: Bing [Bot] and 55 guests