2011-01-14 4 views
0

WPFで2つの図形を描画し、それらをマージしたいと思います。次に、元の図形の1つにドラッグ/ドロップイベントを添付したいと思います。WPFでシェイプをマージして部分的なドラッグ/ドロップを適用する

基本的に、図形の特定の部分をクリックするだけでドラッグできますが、図形全体がドラッグされます。ここで

はいくつかのコードです:

// Set up some basic properties for the two ellipses 
Point centerPoint = new Point(100, 100); 
SolidColorBrush ellipseColor_1 = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)); 
double width_1 = 10; double height_1 = 10; 
SolidColorBrush ellipseColor_2 = new SolidColorBrush(Color.FromArgb(50, 255, 0, 0)); 
double width_2 = 200; double height_2 = 200; 

// Create the first ellipse: A small blue dot 
// Then position it in the correct location (centerPoint) 
Ellipse ellipse_1 = new Ellipse() { Fill = ellipseColor_1, Width = width_1, Height = height_1 }; 
ellipse_1.RenderTransform = new TranslateTransform(point.X - width_1/2, point.Y - height_1/2); 

// Create the second ellipse: A large red, semi-transparent circle 
// Then position it in the correct location (centerPoint) 
Ellipse ellipse_2 = new Ellipse() { Fill = ellipseColor_2, Width = width_2, Height = height_2 }; 
ellipse_2.RenderTransform = new TranslateTransform(point.X - width_2/2, point.Y - height_2/2); 

// ??? 
// How should I merge these? 
// ??? 

// Now apply drag drop behavior to ONLY ellipse_1 
MouseDragElementBehavior dragBehavior = new MouseDragElementBehavior(); 
dragBehavior.Attach(ellipse_1); // This may change depending on the above 

// ... 
// Add new element to canvas 

このコードは、二つの円(大きなものと小さなもの)を作成します。小さなものがクリックされた場合にのみドラッグすることができますが、手動でコードを追加しなくても一緒に移動できるように添付したいと思います。

答えて

1

Grid(またはCanvasStackPanelなど)の両方に入力し、パネル上でドラッグ動作を設定すると、それらは「マージ」されます。 ellipse_2でIsHitTestVisibleをfalseに設定すると、マウスイベントに応答しないため、効果的にドラッグできなくなります。

関連する問題