Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在通用Windows应用程序的右击事件上获取ListView项目内容?_C#_Xaml_Win Universal App_Uwp - Fatal编程技术网

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

C# 如何在通用Windows应用程序的右击事件上获取ListView项目内容?,c#,xaml,win-universal-app,uwp,C#,Xaml,Win Universal App,Uwp,我有一个带有菜单输出的列表视图,如下所示: <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.micros

我有一个带有菜单输出的列表视图,如下所示:

<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>
当用户右键单击或右键点击其中一个listview项目时,会使用“复制”菜单项弹出菜单项。当用户单击“复制”菜单“使用项”时,我希望将listview项内容作为字符串发送到剪贴板


我需要的是在这两个事件之一中获取“right_tapped”listview项内容

((FrameworkElement)e.OriginalSource)。DataContext应该包含右击事件中的项内容。这正是我所需要的。我很感激。
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));
}