在我的 Windows Phone 8.1 通用应用程序中,我在 ListView 中有一个带有按钮的 ItemTemplate ,我需要查看该按钮的 ManipulationStartedManipulationCompleted 事件何时被触发。目前 ManipulationStarted 工作正常,但 ManipulationCompleted 不行。有人可以帮忙解释为什么吗?

快照页面.xaml

<Grid Grid.Row="0" Background="#88686868">
    <Grid.RowDefinitions>
        <RowDefinition Height="130" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <StackPanel Grid.Row="0" Orientation="Vertical" Margin="20,0,0,0">
        <TextBlock Text="{Binding Path=Manager.Account.Username, FallbackValue='loading...'}" Margin="0,12,0,0" Style="{ThemeResource HeaderTextBlockStyle}"/>
        <TextBlock x:Uid="Snaps" Text="SNAPS" Style="{ThemeResource TitleTextBlockStyle}" Typography.Capitals="SmallCaps"/>
    </StackPanel>

    <ScrollViewer x:Name="ScrollViewer" VerticalScrollBarVisibility="Auto"  HorizontalScrollBarVisibility="Disabled"
                  Padding="0,0,0,20" Grid.Row="1" HorizontalContentAlignment="Stretch">
        <ListView HorizontalContentAlignment="Stretch"
                  ItemsSource="{Binding Path=Manager.Account.Snaps}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Button x:Name="ButtonSnap" Style="{StaticResource BasicEmptyButtonStyle}"
                            ManipulationStarting="ButtonSnap_OnManipulationStarting"
                            ManipulationCompleted="ButtonSnap_OnManipulationCompleted"
                            ManipulationMode="All"
                            Command="{Binding ElementName=ItemsControl, Path=DataContext.TryDownloadMediaCommand}"
                            CommandParameter="{Binding}">

                        <!-- Content Here -->

                    </Button>
                </DataTemplate>
            </ListView.ItemTemplate>
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel HorizontalAlignment="Stretch"></VirtualizingStackPanel>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
        </ListView>
    </ScrollViewer>
</Grid>

<Grid Grid.Row="0" x:Name="MediaGrid" Background="#FF000000" IsHitTestVisible="False">
    <Image x:Name="MediaImage" IsHitTestVisible="False"/>

    <Grid Width="45" Height="45" Background="#99000000"
          VerticalAlignment="Top" HorizontalAlignment="Right" Margin="25">
        <TextBlock Text="10" VerticalAlignment="Center" HorizontalAlignment="Center" FontFamily="Segoe WP Semibold" FontSize="24" />
    </Grid>
</Grid>

SnapsPage.cs
    private void ButtonSnap_OnManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e)
    {
        Debug.WriteLine("ButtonSnap_OnManipulationStarting");
        var button = sender as Button;
        if (button == null) return;
        var snap = button.DataContext as Snap;
        if (snap == null) return;
        _relevantSnap = snap;

        _isFingerDown = true;
        _scrollYIndex = ScrollViewer.VerticalOffset;
        _holdingTimer.Start();
    }

    private void ButtonSnap_OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    {
        Debug.WriteLine("ButtonSnap_OnManipulationCompleted");
        _isFingerDown = false;

        if (_isMediaOpen)
            DisposeMediaTidily();
    }

最佳答案

注意:我使用 Windows Phone 8.1 XAML 应用程序(不是 Silverlight)进行了测试

Button 具有 System 的 ManipulationMode ,根据 the docs ,这意味着您不应获得操作事件。

关于c# - ManipulationCompleted 事件未在 Button 上触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23329259/

10-13 08:29