I'm trying to set a default value for a combobox. I have scripts that create the code tables, so writing the code like this is not an option:
<StackPanel>
<ComboBox SelectedValue="CA">
<ComboBoxItem Tag="CO">Colorado</ComboBoxItem>
<ComboBoxItem Tag="CA">California</ComboBoxItem>
<ComboBoxItem Tag="NM">New Mexico</ComboBoxItem>
</ComboBox>
</StackPanel>
Instead I have some code in the XAML:
<StackPanel HorizontalAlignment="Left" Margin="10,5,0,0" Name="PersonStackPanel" Height="60">
<Label VerticalContentAlignment="Top" FontWeight="Normal" Height="28" HorizontalAlignment="Left">Person</Label>
<ComboBox Name="PersonComboBox" Width="312" Props.CodeProvider="MASTCODE.TYPE.ARRA" DisplayMemberPath="NAME" Tag="AA" IsSelected="True" SelectedValuePath="CODE" SelectedItem="{Binding Path=PERSON}"/>
<StackPanel>
i thought Tag="AA" IsSelected="True" would work but it is not.
Any value that is displayed in a combobox has to be present as a selection.
Try:
<ComboBox SelectedIndex="0"/>
Edit: added quotations
You are using
SelectedValuePath="CODE"
so in this case try to set SelectedValue instead of SelectedItem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With