Вопрос

I'm trying to use AutoCompleteBox in my program, but something unwanted happens when I run the application. The problem is that dropdown list of filtered elements shows only name of binded class. When I click on any element, correct value in AutoCompleteBox is set.

Example:

enter image description here

View

<controls:AutoCompleteBox Grid.Column="0"
                          Grid.Row="5"
                          Margin="1"
                          ItemsSource="{Binding RadiatoryComboBoxItem}"
                          SelectedItem="{Binding SelectedRadiator, Mode=TwoWay}"
                          ValueMemberBinding="{Binding Value}"
                          ValueMemberPath="Value"
                          Text="{Binding SelectedRadiator}" />

ViewModel

public IQueryable<ComboBoxKeyAndValue> RadiatoryComboBoxItem
{
    get
    {
        return
        (
            from value in tetraEntities.Radiatory
            select new ComboBoxKeyAndValue
            {
                Key = value.idRadiator,
                Value = value.nameRadiator
            }
        ).ToList().AsQueryable();
     }
}

Please help.

Это было полезно?

Решение

The problem is solved. All what I've done was overriding method ToString() in my class which was binded as a ItemSource.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top