2 つの部分 (ユーザー コントロール) で構成されるスプライン エディターを設計しています。左側のコントロールはDesignerControlで、右側のコントロールはInfoControlです。同じ DataContext を共有します: DesignerVMと
ObservableCollection<SplineVM> SplineVMList;
DesignerControlは、 ItemsSource がSplineVMListにバインドされ、 ItemTemplateが SplineControl として設定されたCanvas (「mycanvas」)としてテンプレート化されたItemsControlです。InfoControlは、SplineVMを表示する ListBox と、SplineVM のプロパティを表示するGridです。
SplineControlには、ドラッグ可能な 4つのポイント (長方形) とこれらのポイントにバインドされる 2 つのラインを含むキャンバスがあります。すべてが機能し、ポイントをドラッグしたり、線を移動したりできます。
<UserControl>
<Canvas Width="300" Height="300" x:Name="mycanvas" Background="Transparent">
<Path x:Name="curve" Stroke="#F02828" StrokeThickness="3">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure>
<PathFigure.Segments>
<PathSegmentCollection x:Name="pathsegment"/>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
<Rectangle x:Name="curvePoint1" Width="10" Height="10" Canvas.Bottom="0" Canvas.Left="0" />
<Rectangle x:Name="curvePoint2" Width="10" Height="10" RadiusX="4" RadiusY="4" Canvas.Bottom="0" Canvas.Left="{Binding ElementName=mycanvas, Path=ActualWidth, Converter={StaticResource mathconverter}, ConverterParameter=(@VALUE/4)}"/>
<Rectangle x:Name="curvePoint3" Width="10" Height="10" RadiusX="4" RadiusY="4" Canvas.Bottom="0" Canvas.Left="{Binding ElementName=mycanvas, Path=ActualWidth, Converter={StaticResource mathconverter}, ConverterParameter=(@VALUE/2)}"/>
<Rectangle x:Name="curvepoint4" Width="10" Height="10" Canvas.Bottom="0" Canvas.Left="{Binding ElementName=mycanvas, Path=ActualWidth, Converter={StaticResource mathconverter}, ConverterParameter=(@VALUE)}"/>
<Line x:Name="line1" Stroke="#dfdfdf" StrokeThickness="1"/>
<Line x:Name="line2" Stroke="#dfdfdf" StrokeThickness="1"/>
</Canvas>
</UserControl>
私の最初の問題は、パス、四角形、および線を保持するためにコンテナー (ここではキャンバス) を使用する必要があることです。
Mycanvasに SplineControl を追加すると適切に配置され、ポイントをすぐにドラッグできますが、別の UserControl を追加すると、前のものの上に配置され、最初の Usercontrol のポイントを選択できません。
最初の userControl から 2 番目までのポイントを選択したいので、IsHitTestVisible を使用したくありません。
私の 2 番目の問題: キャンバスを使用して自分のものを SplineControl に保持するため、キャンバスの外側にポイントをドラッグして操作することができます。
しかし、もう一度考えてみると、ポイントを移動するときにキャンバスのサイズを変更して、常にキャンバス内にポイントがあるようにしたいと考えています。また、mycanvas の比率を考慮して他のポイントの位置を更新します。
この動作を持ち、キャンバスを置き換えることができるコントロールを知っていますか? UserControl の代わりに CustomControl を使用する必要がありますか?
プロジェクトのコンセプトをもう一度考え直さなくてもいいですか?