<ComboBox
x:Name="comboBox"
Margin="281.4,160,259.995,159.958"
d:LayoutOverrides="Height"
ItemsSource="{Binding _US_STATES}"
SelectedIndex="0"
SelectedValue="{Binding SelectedState}"
SelectedValuePath="{Binding Path=_US_STATES/SHORT}"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<Border Padding="2">
<TextBlock Text="{Binding LONG}" />
</Border>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
The above is my xaml version of a ComboBox that I am displaying. I can get it to display correctly because it shows the right data. When I try to get the value that it is selected, it is always RxTracking.model.US_STATES not the value it should be.
The US_STATES looks like this:
public class US_STATES : ObservableObject
{
private string _long;
private string _short;
public string LONG
{
get { return _long; }
set { Set("LONG", ref _long, value); }
}
public string SHORT
{
get { return _short; }
set { Set("SHORT", ref _short, value); }
}
public static ObservableCollection<US_STATES> GetAllStates()
{
ObservableCollection<US_STATES> ALL = new ObservableCollection<US_STATES>
{
new US_STATES {LONG="ALABAMA",SHORT="AL" },
new US_STATES {LONG="Alaska", SHORT = "AK"},
new US_STATES {LONG = "Arizona", SHORT = "AZ"},
etc ...
I am getting this is in the error window:
System.Windows.Data Error: 40 : BindingExpression path error: 'AL' property not found on 'object' ''US_STATES' (HashCode=8402670)'. BindingExpression:Path=AL; DataItem='US_STATES' (HashCode=8402670); target element is 'ComboBox' (Name='comboBox'); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 40 : BindingExpression path error: 'AL' property not found on 'object' ''US_STATES' (HashCode=15232780)'. BindingExpression:Path=AL; DataItem='US_STATES' (HashCode=15232780); target element is 'ComboBox' (Name='comboBox'); target property is 'NoTarget' (type 'Object')