如何在有孔物品上传递CommandParameter?

时间:2016-07-21 07:01:33

标签: windows-phone-8 mvvm-light mvvm-toolkit

如何在有孔物品上传递CommandParameter?

我的xaml代码

   <ListView  Grid.Row="1" Name="ProfilesListView" SelectedItem="{Binding SelectedUser,Mode=TwoWay}" ItemsSource="{Binding Path=ViewAllProfile,Mode=TwoWay}">
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <ItemsWrapGrid Orientation="Horizontal" HorizontalAlignment="Center">
                        </ItemsWrapGrid>
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
                <I:Interaction.Behaviors>
                    <core:EventTriggerBehavior EventName="Holding">
                        <core:InvokeCommandAction Command="{Binding Path=HoldingCommand}" CommandParameter="{Binding ElementName=ProfilesListView,Path=SelectedItem}"  ></core:InvokeCommandAction>
                    </core:EventTriggerBehavior>
                </I:Interaction.Behaviors>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel   Margin="10,0,0,0">
                            <Image  Margin="10" Source="{Binding ImageURL}"   Width="150" Height="150" >
                            </Image>
                            <TextBlock x:Name="userName"  Text="{Binding MenuName}" Foreground="White" HorizontalAlignment="Center"></TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>               
            </ListView>

我的viewmodel是。我没有得到持有项目的详细信息。如何解决这个问题

 _HoldingCommand = new RelayCommand<object>(HoldedUser);

1 个答案:

答案 0 :(得分:0)

不确定这可以通过MVVM绑定直接完成。 持有事件不会立即设置所选项目......

如果您要注册持有事件并使用后面的代码,您会注意到'holded'项目仅在HoldingRoutedEventArgs中已知 - 如下所示:

private async void OnListViewHolding(object sender, HoldingRoutedEventArgs e)
{
   var selectedItemThroughHolding = e.OriginalSource.DataContext as ***Model;
}

所以我的建议是在事件后面使用这个代码并将selectedItem重新路由到那里的viewmodel ......