使用户左键单击gridview的项目,但禁用右键单击并选择xaml中的项目

时间:2013-05-27 13:43:53

标签: windows-8 winrt-xaml

<GridView
                                    Grid.Row="1" 
                                    AutomationProperties.AutomationId="ItemGridView"
                                    AutomationProperties.Name="Grouped Items"
                                    ItemsSource="{Binding ServiceOrderList}"
                                    ItemTemplate="{StaticResource ServiceOrderListItemTemplate}"
                                    SelectedItem="{Binding SelectedServiceOrder, Mode=TwoWay}"
                                    IsSwipeEnabled="false">
                                    <winRtBehaviors:Interaction.Behaviors>
                                        <behaviors:EventToBoundCommandBehavior
                                            Command="{Binding ServiceOrderItemClickCommand}"
                                            Event="Tapped" />
                                    </winRtBehaviors:Interaction.Behaviors>

                                    <GridView.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <WrapGrid Orientation="Vertical" MaximumRowsOrColumns="3" />
                                        </ItemsPanelTemplate>
                                    </GridView.ItemsPanel>
                                </GridView>

我希望能够左键单击gridview的项目但是不想让他们右键单击并选择一个项目,请帮忙。

2 个答案:

答案 0 :(得分:0)

如果您根本不想要选择项目,请设置SelectionMode="None"IsItemClickEnabled="True"以及设置ItemClick事件。

如果您希望选择它们,但只需左键单击,则可以设置IsRightClickEnabled="False"

答案 1 :(得分:0)

另一种方法是将RightTapped事件放在GridView.ItemTemplate中,即实施:e.Handled = true

<GridView>
    <GridView.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="30,10"
                              Width="350" Tapped="Grid_Tapped_1" RightTapped="Grid_RightTapped">
                            <StackPanel Orientation="Vertical">
                                <StackPanel Orientation="Horizontal">
                                    <Image Height="40" Source="{Binding Path=Image}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,-3,11,0"/>
                                    <TextBlock FontSize="24" FontWeight="SemiBold" FontFamily="Segoe WP" Foreground="#232323" Text="{Binding Path=RoomTypeString}" VerticalAlignment="Center"/>
                                </StackPanel>
                                <TextBlock FontSize="24" Text="{Binding Path=RoomCountString}"
                                        Foreground="#232323" FontFamily="Segoe WP"
                                        TextTrimming="CharacterEllipsis"/>
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </GridView.ItemTemplate>
    </GridView>