Windows Phone 8.1操作事件不会触发



我试图在ListView上使用Windows Phone 8.1上的操纵事件,但没有操纵事件发生。指针事件触发,但它们以一种非常奇怪的方式工作,我需要操纵事件。即使我尝试在父元素上触发事件,也不会触发任何事件。我在Youtube上找到了一个我需要的视频,但是它在Windows Phone 8.1上不起作用。还有这个链接,一个人似乎有同样的问题,有人说他们添加的事件只是很好(没有代码片段虽然)。我尝试将事件添加到父元素,没有触发,我尝试使用ListView的ScrollViewer并将事件添加到其中,没有触发,我甚至尝试将ListView更改为ListBox,仍然没有触发事件。如有任何帮助,不胜感激。

    public MainPage()
    {
        this.InitializeComponent();
        this.NavigationCacheMode = NavigationCacheMode.Required;
        ItemLV.DataContext = Items.DealsCollection;
        ItemLV.ManipulationStarted += ItemLV_ManipulationStarted;
    }
    private void ItemLV_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
    {
        throw new NotImplementedException();
    }

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Pivot Grid.Row="1" x:Name="Pivot">
        <PivotItem Margin="0,-5,0,0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <TextBlock Text="frontpage" Foreground="#0072bc" FontSize="30" Margin="5,0,0,0"/>
                <ListView x:Name="ItemLV" IsItemClickEnabled="True" Grid.Row="1" ItemsSource="{Binding}">
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel></StackPanel>
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid x:Name="ItemGrid" Margin="0,2,0,0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="110"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <Image Source="{Binding ImgUrl}" Stretch="Uniform" Canvas.ZIndex="2" Margin="5,5,5,2" VerticalAlignment="Center"/>
                                <Grid Grid.Column="1">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{Binding Title}" 
                                               VerticalAlignment="Center" HorizontalAlignment="Left" 
                                               FontSize="18" TextWrapping="Wrap" Foreground="Black"/>
                                    <StackPanel Orientation="Horizontal" Grid.Row="1">
                                        <TextBlock Text="{Binding Price}" 
                                                   VerticalAlignment="Center" HorizontalAlignment="Left" 
                                                   FontSize="20" TextWrapping="Wrap" Foreground="#0075DB"/>
                                        <Image Source="Assets/flame.gif" Visibility="{Binding Firedeal, Converter={StaticResource ImageBoolConverter}}" VerticalAlignment="Center" Margin="5,3,0,0"/>
                                    </StackPanel>
                                        <TextBlock Text="{Binding ExtraInfo}" Grid.Row="2"
                                                   VerticalAlignment="Center" HorizontalAlignment="Left" 
                                                   FontSize="16" TextWrapping="Wrap" Foreground="#569B1A"
                                                   Visibility="{Binding ExtraInfo, Converter={StaticResource LengthConverter}}">
                                        </TextBlock>
                                    <Grid Grid.Row="3">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="{Binding Store}"
                                                   VerticalAlignment="Bottom" HorizontalAlignment="Left" 
                                                   FontSize="16" TextWrapping="Wrap" Foreground="#666"/>
                                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Column="1">
                                            <TextBlock Text="{Binding Rating}" VerticalAlignment="Bottom"
                                                   FontSize="16" TextWrapping="Wrap" Foreground="Black"/>
                                            <Image Source="Assets/tup.png" VerticalAlignment="Bottom" Margin="2,0,5,0" />
                                            <TextBlock Text="{Binding Comments}" VerticalAlignment="Bottom"
                                                   FontSize="16" TextWrapping="Wrap" Foreground="Black"/>
                                            <Image Source="Assets/comment.png" VerticalAlignment="Bottom" Margin="0,4,3,0" />
                                        </StackPanel>
                                    </Grid>
                                </Grid>
                                <Border BorderThickness="0,2,0,0" BorderBrush="#0072bc" Grid.ColumnSpan="2"/>
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </Grid>
        </PivotItem>
    </Pivot>
</Grid>

你不会得到操作事件,因为ListView有它的操纵模式设置为系统。根据文档:

元素必须具有非None或System的ManipulationMode值才能作为操作事件源。

我不建议改变模式,因为它很可能会停止滚动

试试这个

public MainPage()
{
    this.InitializeComponent();
    this.ItemLV.AddHandler(UIElement.ManipulationStartedEvent,new ManipulationStartedEventHandler(ItemLV_ManipulationStarted), true);
 }

试试这个链接在ListView上水平滚动

相关内容

  • 没有找到相关文章