我有一个 MVVM 项目,一个视图有一个允许多选的网格,
<DataGrid x:Name="DataGridBodegas" ItemsSource="{Binding MyLis}" Grid.Row="1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand Command="{Binding _MyCommand}" CommandParameter="{Binding ElementName=DataGridBodegas,Path=SelectedItems}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
<DataGridTextColumn Header="{x:Static resources:Labels.ACOPIO_SeleccioneBodegas}" Width="Auto" Binding="{Binding StrNombreBodega}" ClipboardContentBinding="{x:Null}"/>
</DataGrid.Columns>
</DataGrid>
在 VM 我有一个 ICommand
public override void CommandSelectionChange(object p)
{
MyList.RemoveAll(x=> x.IntIdBodega != -1);
MyList = p as List<Merlin_INV_Bodegas>; // Allways return Null
}
如果我看一下p object
It is a SelectedItemCollection
that has elements of my target type, 但如果我尝试这样转换
(List<TargetType>)p // Throw exception
p as List<TargetType> // Allways return null
foreach( TargetType t in p)
{
} // Throw exception
我的问题是如何将p正确地投射到我的列表中?