注意需要使用Blend的System.Windows.Interactivity.dll文件。
通过 关联到SelectionChanged事件,当前台获取到SelectedItem时,就会调用ViewModel的ExecuteGetItem方法,获取选择项。
XAML:
Margin="0,0,0,125"
>
CommandParameter="{Binding ElementName=lb_items}">
IsSelected="{Binding Path=IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
>
ViewModel:
public DelegateCommand GetItemCommand { get; set; }
public void ExecuteGetItem(ListBox lb)
{
StandardViewModel model = lb.SelectedItem as StandardViewModel;
}