WPF ComboBox 自定义绑定

WPF ComboBox Custom Binding

我有一个自定义 class,其中两个值是描述,url 附加到 ComboBox。 ComboBox 附加到 class 并按预期填充,但我无法使用 url 值来填充 ComboBox 的文本属性。

            <ComboBox x:Name="platform_url" Grid.Column="1"  HorizontalAlignment="Left" Height="Auto" Margin="3" Grid.Row="0" VerticalAlignment="Center" Width="120"
                    Text="{Binding url, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"
                    ItemsSource="{Binding LocationList}"
                    SelectedItem="{Binding SelectedLocation}"
                      DisplayMemberPath="Description"
                    SelectedValuePath="Url"
                      />

使用以下 class 进行数据填充和控制:

class LocationViewModel : INotifyPropertyChanged
{
    public ObservableCollection<Location> LocationList { get; set; }
    public LocationViewModel()
    {
        LocationList = new ObservableCollection<Location>();
        LocationList.Add(new Location() { Description = "North America", Url = "abc.com" });
    }

    private Location selectedLocation;
    public Location SelectedLocation
    {
        get { return selectedLocation; }
        set
        {
            selectedLocation = value;
            OnPropertyChanged("SelectedLocation");
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string name)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(name));
        }
    }
}
class Location
{
    public string Url { get; set; }
    public string Description { get; set; }
}

我能得到的最好的是正在使用的描述字段,而不是 url 字段。

请帮忙!

成功了

                    <ComboBox x:Name="platform_datacenter" Grid.Column="1"  HorizontalAlignment="Left" Height="Auto" Margin="3" Grid.Row="0" VerticalAlignment="Center" Width="100"
                        SelectedValuePath="moid"
                        SelectedValue="{Binding Path=datacenter, Mode=TwoWay}" 
                        DisplayMemberPath="datacenter"/>