I'm looking for a possibility to set the first item in my combobox as the default value.
I have my view (XAML) with the combobox:
<ComboBox ItemsSource="{Binding SiteScripts, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
SelectedValue="{Binding SelectedSiteScriptId}"
SelectedIndex="0" SelectedValuePath="Id"
DisplayMemberPath="Name" Background="AliceBlue"
Margin="5,10,10,540" Width="100" Height="50"/>
I am binding to my list from the view model in the ItemsSource property of the combobox and my SelectedValue is bound to the ID property item:
public List<SiteCreateMachineScripts> SiteScripts
{
get { return _siteScripts; }
set
{
_siteScripts = value;
NotifyOfPropertyChange();
}
}
public int SelectedSiteScriptId
{
get { return _selectedSiteScriptId; }
set
{
_selectedSiteScriptId = value;
NotifyOfPropertyChange();
}
}
I already tried to set the SelectedIndex = 0 but it didn't work
Thanks for any advice :)