Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:56:03+00:00 2026-06-10T16:56:03+00:00

I’m trying to connect a line between two ellipses where if one was dragged

  • 0

I’m trying to connect a line between two ellipses where if one was dragged the line would move with it. I have a canvas and inside that are two stackpanels… in each stackpanel is an ellipse on the left… content control in the middle… and another ellipse on the right. The idea is to connect a line between the right ellipse from one stackpanel to the left ellipse in the second stackpanel. So far I have this but can’t seem to get much farther as the propertypath being used to do the binding doesn’t make too much sense to me… which is why I have a Canvas in there right now.

Line line = new Line();
line.Stroke = connectedEllipse.Fill;
line.StrokeThickness = 2;

Binding x1 = new Binding();
Binding x2 = new Binding();
Binding y1 = new Binding();
Binding y2 = new Binding();

x1.Path = new PropertyPath(Canvas.LeftProperty);
x2.Path = new PropertyPath(Canvas.LeftProperty);
y1.Path = new PropertyPath(Canvas.TopProperty);
y2.Path = new PropertyPath(Canvas.TopProperty);

x1.Source = y1.Source = connectedEllipse;
x2.Source = y2.Source = (sender as Ellipse);

line.SetBinding(Line.X1Property, x1);
line.SetBinding(Line.X2Property, x2);
line.SetBinding(Line.Y1Property, y1);
line.SetBinding(Line.Y2Property, y2);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:56:05+00:00Added an answer on June 10, 2026 at 4:56 pm

    Ok I’ve hacked up some code which doesn’t use the attached properties method. This probably isn’t “good” code since I wrote it up in 20 minutes but it will get you started.

    MainWindow.xaml

    <Window x:Class="EllipseTest.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:my="clr-namespace:EllipseTest"
            Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded" >
        <Window.Resources>
            <ControlTemplate x:Key="template1">
                <Ellipse Width="60" Height="30" Fill="Blue" />
            </ControlTemplate>
        </Window.Resources>
        <Canvas Name="canvas">
            <my:ExtendedThumb x:Name="thumb1" Canvas.Left ="0" Canvas.Top="0" DragDelta="myThumb_DragDelta" Template="{StaticResource template1}" />
            <my:ExtendedThumb x:Name="thumb2" Canvas.Left ="50" Canvas.Top="20" DragDelta="myThumb_DragDelta" Template="{StaticResource template1}" />
        </Canvas>
    </Window>
    

    MainWindow.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    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;
    
    namespace EllipseTest
    {
       /// <summary>
       /// Interaction logic for MainWindow.xaml
       /// </summary>
       public partial class MainWindow : Window
       {
          Path path;
    
          public MainWindow()
          {
             InitializeComponent();
          }
    
          private void myThumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
          {
             ExtendedThumb thumb = e.Source as ExtendedThumb;
             Canvas.SetLeft(thumb, Canvas.GetLeft(thumb) + e.HorizontalChange);
             Canvas.SetTop(thumb, Canvas.GetTop(thumb) + e.VerticalChange);
             if (thumb == thumb1)
                UpdateLine(thumb, thumb2);
             else
                UpdateLine(thumb1, thumb);
          }
    
          private void UpdateLine(ExtendedThumb firstThumb, ExtendedThumb secondThumb)
          {
             double left1 = Canvas.GetLeft(firstThumb);
             double top1 = Canvas.GetTop(firstThumb);
    
             double left2 = Canvas.GetLeft(secondThumb);
             double top2 = Canvas.GetTop(secondThumb);
    
             thumb1.ConnectingLine.StartPoint = new Point(left1 +firstThumb.ActualWidth / 2, top1 + firstThumb.ActualHeight / 2);
             thumb1.ConnectingLine.EndPoint = new Point(left2 + secondThumb.ActualWidth / 2, top2 + secondThumb.ActualHeight / 2);
    
             thumb2.ConnectingLine.StartPoint = new Point(left2 + secondThumb.ActualWidth / 2, top2 + secondThumb.ActualHeight / 2);
             thumb2.ConnectingLine.EndPoint = new Point(left1 + firstThumb.ActualWidth / 2, top1 + firstThumb.ActualHeight / 2);
    
          }
    
          private void Window_Loaded(object sender, RoutedEventArgs e)
          {
             path = new Path();
             path.Stroke = Brushes.Black;
             path.StrokeThickness = 2;
    
             canvas.Children.Add(path);
    
             LineGeometry line = new LineGeometry();
             path.Data = line;
    
             thumb1.ConnectingLine = line;
             thumb2.ConnectingLine = line;
    
             UpdateLine(thumb1, thumb2);
    
          }
       }
    }
    

    ExtendedThumb.cs

    using System;
    using System.Collections.Generic;
    using System.Windows.Controls.Primitives;
    using System.Windows.Media;
    using System.Linq;
    using System.Text;
    
    namespace EllipseTest
    {
       public class ExtendedThumb : Thumb
       {
          public LineGeometry ConnectingLine { get; set; }
    
          public ExtendedThumb() : base() { ConnectingLine = new LineGeometry(); }
       }
    }
    

    Also, I got the idea from the contents of this link: http://denisvuyka.wordpress.com/2007/10/13/wpf-draggable-objects-and-simple-shape-connectors/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.