1

I am using WPF. I have been battling to solve this problem. I tried to follow several advices from google but it didnt work for me. I cannot manage to default "--Select Car--" in the combobox. I have tried to put Text="--Select Cars--" IsEditable="True" IsReadOnly="True" which is not working. It still displays "Toyota" as default. Look below here:

<DockPanel xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <DockPanel.Resources>
        <x:Array Type="{x:Type sys:String}" x:Key="cmbCarListItems">
            <sys:String>Toyota</sys:String>
            <sys:String>Kia</sys:String>
            <sys:String>Audi</sys:String>
        </x:Array>
    </DockPanel.Resources>
    <ComboBox Name="cmbCarList" 
              Text="--Select Cars--" 
              IsEditable="True"
              Cursor="Hand" 
              IsSynchronizedWithCurrentItem="True" 
              ItemsSource="{StaticResource cmbCarListItems}" 
              SelectionChanged="cmbCarList_SelectionChanged">
    </ComboBox>
</DockPanel>

Your code help much appreciated!!

Mo Patel
  • 2,321
  • 4
  • 22
  • 37
user235973457
  • 331
  • 4
  • 9
  • 24

1 Answers1

2

This was working for me:

<Grid>

    <Grid.Resources>
        <x:Array Type="{x:Type sys:String}" x:Key="cmbCarListItems">
            <sys:String>Toyota</sys:String>
            <sys:String>Kia</sys:String>
            <sys:String>Audi</sys:String>
        </x:Array>
    </Grid.Resources>

    <!-- Not using IsSynchronizedWithCurrentItem="True" -->
    <ComboBox Name="cmbCarList" 
              Text="--Select Cars--" 
              IsEditable="True"
              Cursor="Hand"
              ItemsSource="{StaticResource cmbCarListItems}"  
              SelectionChanged="cmbCarList_SelectionChanged">
    </ComboBox>

</Grid>
meilke
  • 3,280
  • 1
  • 15
  • 31