【问题标题】:DataGrid XAML control can't be scrolled by touchDataGrid XAML 控件无法通过触摸滚动
【发布时间】:2020-04-09 15:55:14
【问题描述】:

我正在开发一个 uwp 应用程序。该应用程序有一个 DataGrid XAML 控件。

我的问题是我可以通过鼠标滚动它,但我不能通过触摸滚动它。奇怪的是,我可以通过两根手指触摸来滚动它。

请告诉我如何解决问题。

这是我的代码。

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Loaded="ContentGrid_Loaded">
        <SplitView x:Name="spritView"
                   IsPaneOpen="{Binding ElementName=HamburgerButton,Path=IsChecked, Mode=TwoWay}"
                   DisplayMode= "CompactInline"
                   PaneBackground="LightGray"
                   PanePlacement="Left"
                   CompactPaneLength ="0"
                   OpenPaneLength="200"
                       Margin="0,48,0,0"
                       >
            <SplitView.Pane>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <ScrollViewer>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
                            <Button x:Name="BtExit" Click="BtExit_Click">
                                <Image Source="/pictuer/left_arrow.png" Height="32"/>
                            </Button>
                            <TextBlock Text="Category" Width="140" Style="{StaticResource TextBlockFontSize1}"/>
                        </StackPanel>

                    </ScrollViewer>
                </Grid>
            </SplitView.Pane>
            <ScrollViewer ZoomMode="Enabled"
                          ScrollViewer.VerticalScrollBarVisibility="Auto"
                          ScrollViewer.VerticalScrollMode="Auto"
                          ScrollViewer.HorizontalScrollBarVisibility="Auto"
                          ScrollViewer.HorizontalScrollMode="Auto"
                          >
                <StackPanel Background="Snow" >
                    <controls: x:Name="dataGrid" AutoGenerateColumns="False"
                                           GridLinesVisibility="All" AlternatingRowBackground="LightCyan"
                                       ItemsSource="{Binding DefuctLists}">
                        <controls:DataGrid.Columns>
                            <controls:DataGridTextColumn Header="Category" Binding="{Binding Item_Lb}" IsReadOnly="True" />
                        </controls:DataGrid.Columns>

                    </controls:DataGrid>
                    <Border Style="{StaticResource borderLineLightGray}" Margin="0,8,0,0"/>
                </StackPanel>
            </ScrollViewer>

        </SplitView>

    </Grid>

【问题讨论】:

    标签: uwp windows-community-toolkit


    【解决方案1】:

    DataGrid XAML 控件无法通过触摸滚动

    为了检查您的代码,我有点困惑,为什么要将DataGrid插入ScrollViewer,以及为什么将DataGrid父面板设置为StackPanel,这将使DataGrid的实际高度更大不是内容的高度,这会使DataGrid无法滚动。

    如果我们删除ScrollViewer 并将StackPanel 替换为Grid,那么DataGrid 将响应触摸滚动。

    <SplitView.Content>
        <Grid>
            <controls:DataGrid
                x:Name="dataGrid"
                AlternatingRowBackground="LightCyan"
                AutoGenerateColumns="False"
                GridLinesVisibility="All"
                >
                <controls:DataGrid.Columns>
                    <controls:DataGridTextColumn
                        Binding="{Binding}"
                        Header="Category"
                        IsReadOnly="True"
                        />
                </controls:DataGrid.Columns>
            </controls:DataGrid>
        </Grid>
    </SplitView.Content>
    

    【讨论】:

    • 嗨,尼科。感谢您的解决方案。正如你告诉我的,我删除了 ScrollViewer 并将 StackPanel 替换为 Grid,DataGrid 最终响应了触摸滚动。问题已经彻底解决了。非常感谢。
    【解决方案2】:

    简单地说,它还没有实现,你不能在 Xbox 和其他触摸设备上滚动。请参阅 GitHub 问题: https://github.com/windows-toolkit/WindowsCommunityToolkit/issues/2864

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 2012-10-19
      • 2017-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多