【问题标题】:WPF: ScrollViewer with more than one DataGrid and LabelWPF:具有多个 DataGrid 和标签的 ScrollViewer
【发布时间】:2014-10-05 02:36:37
【问题描述】:

在我的 WPF 应用程序中,我有一个窗口,其中包含许多动态 DataGrid,顶部带有标签作为标题行。这些元素是 ScrollViewer 的子元素。 如果我向上或向下滚动 ScrollViewer 总是跳到标签。从 DataGrids 的内容中,只有第一列是可见的。 我的 WPF 代码:

<ScrollViewer CanContentScroll="True" PanningMode="VerticalFirst" MouseWheel="ResultDataGrid_OnMouseWheel" x:Name="ResultScrollViewer" Height="Auto">
  <StackPanel x:Name="ResultStackPanel">
  <TextBlock Text="Result" Style="{StaticResource Heading2}" />
    <StackPanel Style="{StaticResource ResultStackPanel}">
       <Label Content="Informations" x:Name="LabelInfo" Style="{StaticResource BoldLabel}"/>
       <DataGrid x:Name="ResultMeta" Style="{StaticResource DataGridStyle}" />
    </StackPanel>
    <StackPanel Style="{StaticResource ResultStackPanel}">
       <Label Content="Statistics" Style="{StaticResource BoldLabel}"/>
       <DataGrid x:Name="ResultStat" Style="{StaticResource DataGridStyle}" />
    </StackPanel>
    <StackPanel Style="{StaticResource ResultStackPanel}">
       <Label Content="Resources" Style="{StaticResource BoldLabel}" />
       <DataGrid x:Name="ResultResources" Style="{StaticResource DataGridStyle}" />
    </StackPanel>
    <!-- ... -->
  </StackPanel>
</ScrollViewer>

【问题讨论】:

    标签: wpf datagrid scroll scrollviewer


    【解决方案1】:

    ScrollViewer 的默认滚动行为是滚动元素。 您可以尝试使用选项CanContentScroll="bool" 更改此行为以将其设置为像素。

    您可以从 MSDN 获得更多信息

    http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.cancontentscroll(v=vs.110).aspx

    但请记住,此选项将强制 ScrollViewer 加载所有可用元素,而不是显示的元素(加载时的性能)。

    【讨论】:

    • 这个属性没有改变。我希望这是每个 DataGrid 高度的依赖项。如果我向下滚动,滚动条的高度就会改变。
    • 您是否尝试过使用 Grid 更改名称为“ResultStackPanel”的子 StackPanel,并使用值 Auto 定义 Grid.Rows,并使用 * 值定义最后一行?
    • 太棒了!如果它解决了您的问题,请接受此作为答案。
    猜你喜欢
    • 1970-01-01
    • 2012-06-23
    • 2018-05-19
    • 2012-05-17
    • 2013-06-22
    • 1970-01-01
    • 2011-11-19
    • 2013-11-20
    • 1970-01-01
    相关资源
    最近更新 更多