我有一个ListBox绑定到ObservableCollection
客户。这样做的XAML代码:项目选择WPF调用函数(使用MVVM范例)
<ListBox x:Name="lb_Customers" Height="683" ItemsSource="{Binding Path=Customers, UpdateSourceTrigger=PropertyChanged}">
<ListBox.ItemTemplate>
<DataTemplate>
<Label Margin="0,0,0,0" Padding="0,0,0,0" Content="{Binding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这点到一些代码在我MainViewModel
类:
public ObservableCollection<Customer> Customers
{
get { return _customers; }
set
{
Set("Customers", ref _customers, value);
this.RaisePropertyChanged("Customers");
}
}
当我选择在这个列表框中一个客户,我想执行一些代码,去编辑客户的订单历史。
但是,我不知道如何使用DataBinding/CommandBinding来做到这一点。
我的问题:我甚至在哪里开始?
如何'SelectedValue'从'SelectedItem'不同?试图绑定SelectedItem没有奏效,但我会尝试这个。我很好奇为什么一个人在另一个人上工作。 – Emily
http://stackoverflow.com/questions/4902039/difference-between-selecteditem-selectedvalue-and-selectedvaluepath这个SO线程很好地描述了SelectedValue和SelectedItem之间的区别 – EtherDragon