在 Windows Phone 8 上启用操作

Enable Manipulation On Windows Phone 8

我从 here 中找到了以下代码:

private void Grid_ManipulationStarted_1(object sender, ManipulationStartedRoutedEventArgs e)
    {
        initialpoint = e.Position;
    }

    private void Grid_ManipulationDelta_1(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        if (e.IsInertial)
        {
            Point currentpoint = e.Position;
            if (currentpoint.X - initialpoint.X >= 500)//500 is the threshold value, where you want to trigger the swipe right event
            {
                System.Diagnostics.Debug.WriteLine("Swipe Right");
                e.Complete();
            }
        }
    }

还有我的 Xaml:

<Page
x:Class="MyApp.DetailPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Viewbox x:Name="MainViewbox" Stretch="Uniform" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="1, 1, 1, 1" ManipulationDelta="Grid_ManipulationDelta_1" ManipulationStarted="Grid_ManipulationStarted_1">
    <Grid ManipulationDelta="Grid_ManipulationDelta_1" ManipulationStarted="Grid_ManipulationStarted_1" Background='Transparent'>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TextBlock x:Name="IDAndTitleTxt" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Row="1" TextAlignment="Center" Height="Auto" Width="Auto" FontSize="20" Foreground="White"/>
        <TextBlock x:Name="IssueType" HorizontalAlignment="Center" VerticalAlignment="Top" Text="Code Defect" MaxHeight="10" Height="Auto" Width="Auto" Foreground="White" FontSize="4"/>
        <TextBlock x:Name="UserAssignedTo" HorizontalAlignment="Center" VerticalAlignment="Top" Height="Auto" Width="Auto" Grid.Row="3" Foreground="White" FontSize="8"/>
        <TextBlock x:Name="StateSubstate" HorizontalAlignment="Center" VerticalAlignment="Top" Text="Active / In Progress" Height="Auto" Width="Auto" Grid.Row="4" Foreground="White" FontSize="8"/>
        <Button x:Name="BackBtn" Content="Back" HorizontalAlignment="Left" VerticalAlignment="Top" Height="40" Width="40" Grid.RowSpan="2" Grid.Row="0"/>
        <ScrollViewer Height="260" Width="200" HorizontalScrollBarVisibility="Disabled" Grid.Row="2" Canvas.Top="60" Canvas.Left="340">
            <TextBlock Width="195" TextWrapping="Wrap" FontSize="5" x:Name="DescriptionTxt"/>
        </ScrollViewer>
   </Grid>
</Viewbox>

我的问题是,无论我向各个方向滑动屏幕多少次,这两个操作事件都不会触发。我在事件处理程序上设置了断点以确认这一点。其他人已经问过同样的问题 here 但没有答案。看到这个问题是两年多前的问题了,我正在重写它。

此外,我的网格位于页面中的视图框内(不是 window)。

感谢任何帮助:)。

您需要添加背景画笔 - 例如 Background="Transparent" - 以便它接收输入事件。

我猜你的意思是 Windows Phone 8.1 运行时应用程序?因为在 silverlight 中它工作正常。 为此,您应该将网格的 ManipulationMode 设置为 All。在我的测试中,即使没有背景颜色(这在 silverlight 应用程序中是必需的),它也能正常工作。

如果您只需要一部分操作,则应使用最适合您需要的模式。