<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>
上記は私が表示しているComboBoxのxamlバージョンです。正しいデータが表示されるので、正しく表示されるようにすることができます。選択された値を取得しようとすると、常にRxTracking.model.US_STATESになります。wpfコンボボックスSelectedValueプロパティの代わりにクラス名を取得
US_STATESは次のようになります。私はこれを取得しています
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 ...
はエラー・ウィンドウ内にある:
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')
[WPF IsEditable = trueの可能な複製オブジェクトで埋められたComboBoxは、選択されたアイテムとしてToString()を表示します](https://stackoverflow.com/questions/1844156/wpf-iseditable-true-combobox-filled-with-オブジェクト - 表示 - the-tostring-as-the) –