Reputation: 1290
I need my ComboBox's first item to be selected when loaded.
XAML:
<ComboBox x:Name="CreateLstBoxFormat" HorizontalAlignment="Left" Margin="27,334,0,0" IsSynchronizedWithCurrentItem="True" VerticalAlignment="Top" Width="90" SelectedValuePath="Content" SelectedIndex="0" SelectedItem="{Binding CreateFormatSelectedItem, Mode=TwoWay}">
<ComboBox.ItemsSource>
<x:Array xmlns:sys="clr-namespace:System;assembly=mscorlib" Type="{x:Type sys:String}">
<sys:String>MXF</sys:String>
<sys:String>Quicktime MOV</sys:String>
<sys:String>DPX</sys:String>
<sys:String>TIF</sys:String>
<sys:String>TGA</sys:String>
<sys:String>CIN</sys:String>
<sys:String>EXR</sys:String>
</x:Array>
</ComboBox.ItemsSource>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding Create_FormatSelectCommand}"
CommandParameter="{Binding YourCommandParameter}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
I expected MXF
to be initially selected in the combo box on opening of the window.
I'm using the SelectedItem
property to fire an event when the selected item has changed.
Upvotes: 0
Views: 97
Reputation: 3164
Try using SelectedItem
property:
<ComboBox Name="myComboBox"
ItemsSource="{Binding}"
DisplayMemberPath="Description"
SelectedItem="{Binding Path=id}"
IsSynchronizedWithCurrentItem="True"
SelectedIndex="0" />
Upvotes: 1
Reputation: 1853
I think using
SelectedIndex="0(or your desired index)"
will do that for you, even if you are working with MVVM approach. if you don't select anything then it will always show it as blank initially.
Upvotes: 0