WPF Combobox DefaultValue (Please Select)

user3428422 picture user3428422 · Apr 17, 2014 · Viewed 79.6k times · Source

Hi I have a WPF Combobox which shows a list of Enums. Code is below.

    <ComboBox HorizontalAlignment="Left" 
              Margin="139,299,0,0" 
              VerticalAlignment="Top" 
              ItemsSource="{Binding Source={StaticResource Enum}}"
              Width="78"/> 

However, when the view is loaded, it shows the first enum in the list, but I would like it to show 'Please Select', so is there XAML to do this (C# in the view if needs be..)

Thanks

Answer

user3428422 picture user3428422 · Apr 17, 2014

All good answers that has been supplied, but I used the following to solve my problem

<ComboBox SelectedIndex="0">
    <ComboBox.ItemsSource>
        <CompositeCollection>
            <ListBoxItem>Please Select</ListBoxItem>
            <CollectionContainer Collection="{Binding Source={StaticResource YOURDATASOURCE}}" />
        </CompositeCollection>
    </ComboBox.ItemsSource>
</ComboBox>

Thanks for everyone who has helped!