WPF:使用 GridSplitter 触发内容调整大小

发布于 2024-07-23 11:57:01 字数 1102 浏览 2 评论 0原文

我试图强制网格/扩展器重新评估它是否需要滚动条,因为它显示为空。

我正在使用此布局:

<Grid>
  <toolstrip /> <!-- fixed height row -->
  <Scrollviewer>  <!-- * height -->
    <Grid> <!-- all rows are 'Auto' height -->
      <Expander />
      <Expander> <!-- this one stretches far too high -->
        <WPF Toolkit: DataGrid />
      <Expander>
      <GridSplitter/>
      <Expander />
    <Grid>
  </Scrollviewer>
  <stackpanel />   <!-- fixed height row -->
<Grid>

初始化窗口时,DataGrid(WPF 工具包)绑定到一个属性。 通过一些调查,我意识到当窗口初始化时,GridView 中的列以大约 10 像素宽开始,然后添加内容,然后根据 XAML 中的大小调整它们的大小(全部使用星形宽度) - 例如:2*)。 这会导致网格大小调整为窗口显示时所需高度的大约 6 倍,然后它不会弹回,查看窗口底部内容的唯一方法是滚动或移动 GridSplitter回到原来的位置并调整窗口大小。 我还没有设置任何东西的 VerticalAlignment 属性。

到目前为止,我已经在问题扩展器上尝试了以下所有称为 InvalidateArrange()、InvalidateVisual();、InvalidateMeasure() 和 UpdateLayout() 的方法,以及在网格上尝试了 InvalidateArrange()、InvalidateScrollInfo()、InvalidateVisual() 和 UpdateLayout() 的方法在它之上,但它不会退缩。

有什么方法可以强制它不强制 DataGrid 中列的宽度吗?

I'm trying to force a grid/expander to reevaluate whether it needs a scrollbar, as it's showing emptiness.

I'm using this layout:

<Grid>
  <toolstrip /> <!-- fixed height row -->
  <Scrollviewer>  <!-- * height -->
    <Grid> <!-- all rows are 'Auto' height -->
      <Expander />
      <Expander> <!-- this one stretches far too high -->
        <WPF Toolkit: DataGrid />
      <Expander>
      <GridSplitter/>
      <Expander />
    <Grid>
  </Scrollviewer>
  <stackpanel />   <!-- fixed height row -->
<Grid>

The DataGrid (WPF Toolkit) is bound to a property when the Window is initialized. Through some investigating, I've realized that when the window is initialized, the columns in the GridView start at about 10 pixels wide, then the content is added, then they're resized based on the sizes in the XAML (All using star widths - eg: 2*). This causes the grid to resize to about 6 times the height it needs to be as the window is showing, then it doesn't spring back and the only way to see what's at the bottom of the window is to either scroll or move the GridSplitter back up to where it should be and resize the Window. I haven't set the VerticalAlignment properties on anything.

So far I've tried all of the following called InvalidateArrange(), InvalidateVisual();, InvalidateMeasure() and UpdateLayout() on the problem expander and InvalidateArrange(), InvalidateScrollInfo(), InvalidateVisual() and UpdateLayout() on the Grid above it but it won't shrink back.

Is there any way I can force it to short of forcing the width of the columns in the DataGrid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度° 2024-07-30 11:57:01

尝试在 ScrollViewer 上设置这些属性:

<ScrollViewer CanContentScroll="True"
              VerticalScrollBarVisibility="Auto" 
              HorizontalScrollBarVisibility="Auto">
    ... content ...
</ScrollViewer>

如果这不起作用,您能否提供更准确的 XAML 表示。 此外,深入了解 ScrollViewer 可能会有所帮助。

Try setting these properties on the ScrollViewer:

<ScrollViewer CanContentScroll="True"
              VerticalScrollBarVisibility="Auto" 
              HorizontalScrollBarVisibility="Auto">
    ... content ...
</ScrollViewer>

If that doesn't work, can you provide a more exact representation of your XAML. Also, taking a look at the ScrollViewer in depth may help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文