如何在通用Windows应用程序的RightTapped事件上获取ListView项目内容?

时间:2015-12-24 00:07:56

标签: c# xaml win-universal-app uwp

我有一个带有MenuFlyout的ListView,如下所示:

<Page
x:Class="BibleApp.View.BiblePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BibleApp.View"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:data="using:BibleApp.Domain" Loaded="Page_Loaded">

<Page.Resources>
    <DataTemplate x:Key="VerseListDataTemplate" x:DataType="data:Verse">
        <Grid x:Name="gridVerses" Padding="0,20,0,0">
            <TextBlock Text="{x:Bind Number}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
            <TextBlock Text="{x:Bind Text}"  Margin="30,0,0,0" TextWrapping="Wrap" VerticalAlignment="Center" Width="auto" />
        </Grid>
    </DataTemplate>
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">        

    <ListView x:Name="lvVerses" 
              Margin="10,100,10,10" 
              Height="auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
              ItemTemplate="{StaticResource VerseListDataTemplate}"
              SelectionMode="Multiple"                  
              SelectionChanged="lvVerses_SelectionChanged"
              RightTapped="lvVerses_RightTapped"
              IsRightTapEnabled="True">

        <ListView.Resources>
            <MenuFlyout x:Name="menuFlyout">
                <MenuFlyout.Items>
                    <MenuFlyoutItem Name="Copy" Text="Copy" Click="Copy_Click"/>
                </MenuFlyout.Items>
            </MenuFlyout>
        </ListView.Resources>

    </ListView>
</Grid>

在后面的代码中我得到了这些:

private void Copy_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{                        
    DataPackage dataPackage = new DataPackage();
    dataPackage.RequestedOperation = DataPackageOperation.Copy;
    dataPackage.SetText("Hello World!");
    Clipboard.SetContent(dataPackage);
}

private void lvVerses_RightTapped(object sender, Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
{            
    menuFlyout.ShowAt(lvVerses, e.GetPosition(this.lvVerses));
}

当用户右键单击或右键点击其中一个listview项时,将使用&#34;复制&#34; MenuFlyoutItem。当用户点击&#34;复制&#34; MenuFlyoutItem我想将listview项目内容作为字符串发送到剪贴板。

我需要的是获得&#34; right_tapped&#34; listview项目内容在这两个事件之一。

0 个答案:

没有答案