【问题标题】:How to pass CommandParameter on holed item?如何在有孔的项目上传递 CommandParameter?
【发布时间】:2016-11-24 15:04:28
【问题描述】:

如何在有洞的物品上传递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>

我的视图模型是。我没有得到持有物品的详细信息。如何解决这个问题

 _HoldingCommand = new RelayCommand<object>(HoldedUser);

【问题讨论】:

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


    【解决方案1】:

    不确定这是否可以直接通过 MVVM 绑定来完成。 举行事件不会立即设置所选项目...

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

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

    所以我的建议是在事件后面使用此代码并将 selectedItem 重新路由到那里的视图模型...

    【讨论】:

      猜你喜欢
      • 2012-12-14
      • 1970-01-01
      • 2012-05-13
      • 2022-01-26
      • 2016-04-27
      • 1970-01-01
      • 2012-09-04
      • 2017-08-06
      • 1970-01-01
      相关资源
      最近更新 更多