我正在开发一个图形编辑器,当拖动超出顶部或左边框时滚动有问题。当我向下或向右拖动节点时,它可以工作。 XAML:
<ScrollViewer>
<GraphSpace />
</ScrollViewer>
GraphSpace扩展了Canvas。 在GraphSpace中重载了MeasureOverride:
protected override Size MeasureOverride(Size availableSize)
{
base.MeasureOverride(availableSize);
double width = base
.InternalChildren
.OfType<UIElement>()
.Max(i => i.DesiredSize.Width + (double)i.GetValue(GraphArea.XProperty) + 20);
double height = base
.InternalChildren
.OfType<UIElement>()
.Max(i => i.DesiredSize.Height + (double)i.GetValue(GraphArea.YProperty) + 20);
return new Size(width, height);
}
我该如何解决?