Подтвердить что ты не робот

Как передать список selectitem как параметр команды кнопкой?

Вот моя ситуация:

<ListBox ItemsSource="{Binding Path=AvailableUsers}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=Id}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
<Button Command="{Binding Path=Load}" CommandParameter={???? What goes here ????}/>

Я хочу передать идентификатор, который в настоящее время выбран в ListBox. У меня есть viewmodel за кулисами, который выглядит примерно так:

public class ViewModel : DependencyObject
{
    ICommand Load { get; set; }

    // dependency property but I didn't bother to write it out like one
    List<User> AvailableUsers { get; set}
}

Как я могу отправить текущий выбранный элемент с помощью xaml?

4b9b3361

Ответ 1

Попробуйте следующее:

  • Назовите свой список
  • Обновите CommandParameter до:

    CommandParameter = "{Binding ElementName = listBox1, Path = SelectedItem}"