[이 질문에 해당] 클래스가 두 개 있습니다. 첫째, XYAxes2
은 FrameworkElement
입니다. XAxis
(또한 FrameworkElement
까지 확장)을 원하는 위치에 배치하기 위해 MeasureOverride
및 ArrangeOverride
을 재정의합니다.FramworkElement 자식을 배치하지 않도록 정렬 FramworkElement
XYAxes2
(부모)
Scale XAxis =//...
protected override Size MeasureOverride(Size availableSize) {
XAxis.Measure(availableSize);
return (Size)availableSize;
}
protected override Size ArrangeOverride(Size finalSize) {
XAxis.Arrange(new Rect(50, 50, 100, 200));
return finalSize;
}
Scale
맞춤 그린 성분이다. Scale
(자식)이 함수 디버깅 ActualWidth
항상 폭 ArrangeOverride
설정보다는 상위의 폭이면
가 100 자식 그러나 ArrangeOverride
의해 지정된 영역에 잘린
protected override void OnRender(DrawingContext cx) {
ValidateTicks();
if (Orientation == Orientation.Horizontal) {
cx.DrawLine(Pen, new Point(-.5, .5), new Point(ActualWidth - .5, .5));
foreach (double tick in _ticks.Keys) {
double val = ScaleTransformCallback(tick);
double x = -0.5 + (int)((val - MinValue) * ActualWidth/(MaxValue - MinValue));
cx.DrawLine(Pen, new Point(x, .5), new Point(x, TickLength - .5));
FormattedText txt = _ticks[tick];
cx.DrawText(txt, new Point(x - txt.Width/2, TickLength + TextMargin));
}
} else {
double Left = maxTextWidth + 2 * TextMargin;
double Right = this.TickLength + Left;
cx.DrawLine(Pen, new Point(Right - .5, +.5), new Point(Right - .5, ActualHeight + .5));
foreach (double tick in _ticks.Keys) {
double val = ScaleTransformCallback(tick);
double y = -0.5 + ActualHeight - (int)((val - MinValue) * ActualHeight/(MaxValue - MinValue));
cx.DrawLine(Pen, new Point(Right - .5, y), new Point(Left - .5, y));
FormattedText txt = _ticks[tick];
cx.DrawText(txt, new Point(Left - txt.Width - TextMargin, y - txt.Height/2));
}
}
}
.
이 함수 중 하나에서 뭔가 잘못 되었나요?
편집 :XAxis.Measure(100,200)
을 ArrangeOverride
에 삽입하면 문제가 해결 된 것 같습니다. 확실히 배열이 무효화 될 때마다 Measure
에 전화 할 필요가 없습니다. InvalidateArrange
은 암시 적으로 InvalidateMeasure
을 호출해야합니다. 누구든지이 문제의 원인을 밝힐 수 있습니까?
누구나 DesiredSize
과 ActualWidth/Height
이 실제로 설정되었는지 (분명히 내 코드로 설정되지 않음) 알 수 있습니까?
DesiredSize는 일반적으로 Mesasure 패스 후에 설정되며, ActualWidth/Height는 컨트롤이 배열/렌더링 (?) 된 후에 설정됩니다. 그것의 소리에 의해 당신은 Measure (double.PositiveInfinity, doublePositiveInfinity)를 호출 할 필요가 있습니다; 결국 Draw *가 Measure/Arrange 레이아웃 패러다임에 맞지 않을 것이라고 생각합니다. –