以下是我的情况:
<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中当前选中的Id。我有一个幕后的视图模型,基本上是这样的:
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发送当前选定的项目?
答案 0 :(得分:64)
试试这个:
CommandParameter =“{Binding ElementName = listBox1,Path = SelectedItem}”