2
У меня есть пользовательский класс с двумя значениями, являющимися описанием и URL-адресом, который прилагается к ComboBox. ComboBox присоединяется к классу и заполняет, как ожидалось, но я не могу значение url заполнить текстовый атрибут ComboBox.WPF ComboBox Custom Binding
<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 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.
Пожалуйста, помогите!
Как вы хотите, чтобы показать, как '' Description' и свойства Url' в вашем 'ComboBox'? –