1

Polyline のデュアルであるカスタム フレームワーク要素があります。この要素は、ポリラインのポイントの位置にマーカーを描画するように設計されており、オーバーレイとして機能します。

ポイントの描画には成功しましたが、Polyline などの法線形状にある Stretch="Fill" 機能を実装する方法に途方に暮れています。クラスの私のコードは以下のとおりです。

これに Stretch 機能を追加する方法について誰かが教えてくれたら幸いです。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using ReactiveUI;

namespace Weingartner.WPF
{
    public class PolyMarkers : FrameworkElement
    {
        static PolyMarkers()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(PolyMarkers), new FrameworkPropertyMetadata(typeof(PolyMarkers)));
        }

        public PointCollection Points
        {
            get { return (PointCollection)GetValue(PointsProperty); }
            set { SetValue(PointsProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Points.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PointsProperty =
            DependencyProperty.Register(
                "Points", 
                typeof(PointCollection), 
                typeof(PolyMarkers), 
                new PropertyMetadata(new PointCollection()));

        private VisualCollection Children;

        public PolyMarkers()
        {

            this.WhenAny(t => t.Points, x =>
            {
                return x.Value.Select(p =>
                {
                    return CreateDrawingVisualEllipses(p, 10, 10);
                });

            }).Subscribe(x =>
            {
                foreach (var shape in x)
                {
                    AddVisualChild(shape);
                }
                InvalidateMeasure();
                InvalidateArrange();
                InvalidateVisual();
            });


        }

        private DrawingVisual CreateDrawingVisualEllipses(Point location, int dx, int dy)
        {
            DrawingVisual drawingVisual = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            drawingContext.DrawEllipse(Brushes.Maroon, null, location, dx, dy);
            drawingContext.Close();

            return drawingVisual;
        }


        // Provide a required override for the VisualChildrenCount property.
        protected override int VisualChildrenCount
        {
            get { return Children.Count; }
        }

        // Provide a required override for the GetVisualChild method.
        protected override Visual GetVisualChild(int index)
        {
            if (index < 0 || index >= Children.Count)
            {
                throw new ArgumentOutOfRangeException();
            }

            return Children[index];
        }
    }
}
4

1 に答える 1

2

最も簡単な方法はViewbox、要素のコンテンツ全体をラップして、スケーリングを処理できるようにすることです。コントロール内のより低いレベルでそれを実行したい場合は、すべてのMeasureメソッドとArrangeメソッドをオーバーライドし、すべてのスケーリングを手動で実行する必要があります。これは、多くの(非常にエラーが発生しやすい)作業になる可能性があります。

于 2013-01-28T18:18:41.820 に答える