WPF如果ScrollViewer中的孩子们调整,将ScrollViewer中自动更新它的程度呢? [英] WPF if the children of a scrollviewer resize, will the scrollviewer automatically update its extent?

查看:1334
本文介绍了WPF如果ScrollViewer中的孩子们调整,将ScrollViewer中自动更新它的程度呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的第一个问题是,ScrollViewer中是否自动更新它的程度或者我是否需要调用的ScrollViewer,迫使它更新无效措施。

So My first question is whether the scrollviewer automatically updates its extent or whether I need to call invalidate measure on scrollviewer to force it to update.

无论如何,我有带内的曲线图一的ScrollViewer。当我使用缩放选择框我希望轴划分单元改变时,ScrollViewer中的内容发生变化,ScrollViewer中来重新计算其新的程度,最后滚动到正确的偏移量。

Anyway, I have a scrollviewer with a graph inside. When I use a zoom select box I want the axis division unit to change, the scrollviewer's content to change, scrollviewer to recalculate its new extent, and finally to scroll to the correct offset.

目前我已经AxisDivisionUnit作为一个依赖属性上更新无效的内容,然后重新测量的内容和重绘。

Currently I have AxisDivisionUnit as a Dependency Property that on update invalidates the contents, which then remeasures the content and redraws.

        sg.InvalidateMeasure();
        sg.UpdateLayout();
        sg.DrawSignal();

和另一个类,

           AxisDivisionUnit = NewAxisDivisionUnit;

          //need to scroll to new position based on location chosen with zoombox
          //calculate position of originalOffsetinTimescaleunits on new scale.
          double NewNumberOfPixelsPerUnit = (double)(NUMBER_OF_DEVICE_INDEP_PIXELS_PER_INCH) / AxisDivisionUnit;
          double NewPixelOffset = HorizontalUnitOffset * NewNumberOfPixelsPerUnit;
          if (NewPixelOffset > sv.ExtentWidth)
          {
            NewPixelOffset = sv.ExtentWidth - sv.ViewportWidth;
          }
          sv.ScrollToHorizontalOffset(NewPixelOffset);



不过,该ScrollViewer中程度上不是由我希望滚动的时间进行更新,因此代码没有按' T功能如我所愿。我想我也可能会在这里呼吁invalidatemeasure上的ScrollViewer,但后来我如何确保AxisDivision有什么改变?我需要确保由于内容的大小取决于属性。

However, The scrollviewer extent has not updated by the time I wish to scroll, so the code doesn't function as I wish. I guess I could also potentially call invalidatemeasure on the scrollviewer here, but then how do i ensure that the AxisDivision has changed? I need to ensure that since the size of the content depends on the property.

推荐答案

您好我有同样的麻烦,我固定它通过调用UpdateLayout请ScrollViewer控件的方法检查scrollviewer.extent属性之前。

Hi I had the same trouble and I fixed it by calling updateLayout method of scrollviewer control before check scrollviewer.extent property.

我希望它能帮助。

这篇关于WPF如果ScrollViewer中的孩子们调整,将ScrollViewer中自动更新它的程度呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆