I'm trying to bind a ComboBox SelectedValue
to a string
. The Binding
works flawlessly. However, one of my ComboBoxItem's IsSelected
is set to True
, but for some reason when I launch the application, none of the items is selected, the SelectedValue
is blank and I need to re-select the item I want.
Here's my code:
XAML:
<ComboBox x:Name="SearchOptions"
FontFamily="Times New Roman"
Foreground="DarkRed"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
Grid.Column="2" Margin="10,0,0,0" Height="20"
SelectedValue="{Binding SearchType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ComboBoxItem x:Name="Contact" Content="A" FontFamily="Times New Roman" Foreground="DarkRed" HorizontalContentAlignment="Center" IsSelected="True"/>
<ComboBoxItem x:Name="Paper" Content="B" FontFamily="Times New Roman" Foreground="DarkRed" HorizontalContentAlignment="Center"/>
</ComboBox>
ViewModel Code-Behind:
private string m_serachType;
public string SearchType
{
get { return m_serachType; }
set
{
m_serachType = value;
OnPropertyChanged("SearchType");
}
}
My ViewModel
class implements INotifyPropertyChanged
.
Any ideas?