【问题标题】:Windows Phone 8.1 Manipulation Events do not fireWindows Phone 8.1 操作事件不会触发
【发布时间】:2014-07-08 04:55:43
【问题描述】:

我正在尝试在 ListView 上使用 Windows Phone 8.1 上的操作事件,但没有触发任何操作事件。指针事件触发,但它们以一种非常奇怪的方式工作,我需要操作事件。即使我尝试在父元素上触发事件,也不会触发。我找到了一个Youtube Video,它可以满足我的需要,但是它在 Windows Phone 8.1 上不起作用。还有这个Link,一个人似乎遇到了同样的问题,有人说他们添加了事件就好了(虽然没有代码sn-p)。我尝试将事件添加到父元素并且没有触发任何事件,我尝试获取 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>

【问题讨论】:

  • 你找到解决办法了吗?

标签: c# xaml event-handling windows-phone-8.1


【解决方案1】:

您不会收到操作事件,因为 ListView 将其 ManipulationMode 设置为 System.根据the docs

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

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

【讨论】:

    【解决方案2】:

    试试这个

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

    试试这个链接Horizontal scroll on ListView

    【讨论】:

    • 对于ManipulationCompleted 我不得不使用这个:control.AddHandler(System.Windows.UIElement.ManipulationCompletedEvent, new EventHandler&lt;System.Windows.Input.ManipulationCompletedEventArgs&gt;(control_ManipulationCompleted), true);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多