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 3402244
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:06:51+00:00 2026-05-18T05:06:51+00:00

The following method thrwos an exception in the line: Point childPosition = vb.TransformToAncestor(surfaceWindow).Transform(new Point(0,

  • 0

The following method thrwos an exception in the line:

Point childPosition = vb.TransformToAncestor(surfaceWindow).Transform(new Point(0, 0));

But if you look at the code, the vb is surely a child of surfaceWindow. So why isn’t this working?

if (!isExpanded())
            {
                Viewbox vb = new Viewbox();

                ClassMetricView metricView = new ClassMetricView();
                metricView.Width = 300;
                metricView.Height = 300;
                metricView.ClassName = this.name;
                metricView.NumberOfMetrics = 6;
                metricView.LOC = this.getLoc();
                metricView.FanIn = this.getFanIn();
                metricView.FanOut = this.getFanOut();
                metricView.buildComponent();
                vb.Child = metricView;
                vb.AddHandler(StackPanel.SizeChangedEvent, new System.Windows.SizeChangedEventHandler(SizeChangedHandler));

                surfaceWindow.ClassScatter.Items.Add(vb);
                this.setExpanded(true);

                //Create line to connect these UI elements

                Point parentPosition = surfaceWindow.RootContainer.TransformToAncestor(surfaceWindow).Transform(new Point(0, 0));
                Point childPosition = vb.TransformToAncestor(surfaceWindow).Transform(new Point(0, 0));
                Line line = new Line();
                line.X1 = parentPosition.X;
                line.Y1 = parentPosition.Y;
                line.X2 = childPosition.X;
                line.Y2 = childPosition.Y;
                line.Stroke = System.Windows.Media.Brushes.Black;
                line.StrokeThickness = 2;
                surfaceWindow.RootGrid.Children.Add(line);
            }

EDIT: I found maybe an answer to my problem:

Error when using TransformToAncestor: "The specified Visual is not an ancestor of this Visual."

the problem is, I don’t understand the solution. Can anyone explain?

EDIT 2: I tried to implement this dispatcher. But still the same exception is thrown. Any hints would be really great!

 public void expand(SurfaceWindow1 surfaceWindow)
        {
            _surfaceWindow = surfaceWindow;
            Logging.Logger.getInstance().log("Expand class " + name);

            if (!isExpanded())
            {
                Viewbox vb = new Viewbox();

                ClassMetricView metricView = new ClassMetricView();
                metricView.Width = 300;
                metricView.Height = 300;
                metricView.ClassName = this.name;
                metricView.NumberOfMetrics = 5;
                metricView.NumberOfRevisions = 6;
                metricView.MetricsName = new string[] { "LOC", "FanIn", "FanOut", "NOM", "McCabe"};
                int[,] values = { { 10, 10, 10, 10, 10}, {20, 20, 20, 20, 20}, {30, 30, 30, 30, 30}, {40, 40, 40, 40, 40}, {50, 50, 50, 50, 50}, {60, 60, 60, 60, 60} };
                metricView.Metrics = values;
                metricView.buildComponent();
                vb.Child = metricView;
                vb.AddHandler(StackPanel.SizeChangedEvent, new System.Windows.SizeChangedEventHandler(SizeChangedHandler));

                surfaceWindow.ClassScatter.Items.Add(vb);
                this.setExpanded(true);

                //Create line to connect these UI elements
                System.Threading.Thread thread = new System.Threading.Thread(
    new System.Threading.ThreadStart(
      delegate()
      {
          vb.Dispatcher.Invoke(
            System.Windows.Threading.DispatcherPriority.Normal,
            new Action(
              delegate()
              {
                  SetStatus(vb);
              }
          ));
      }
  ));

                thread.Start();
            }
        }

        private void SetStatus(Viewbox vb)
        {

            Point parentPosition = _surfaceWindow.RootContainer.TransformToAncestor(_surfaceWindow).Transform(new Point(0, 0));
            Point childPosition = vb.TransformToAncestor(Window.GetWindow(vb)).Transform(new Point(0, 0));
            //Point childPosition = new Point(0, 0);

            Line line = new Line();
            line.X1 = parentPosition.X;
            line.Y1 = parentPosition.Y;
            line.X2 = childPosition.X;
            line.Y2 = childPosition.Y;
            line.Stroke = System.Windows.Media.Brushes.Black;
            line.StrokeThickness = 2;
            _surfaceWindow.RootGrid.Children.Add(line);

            Console.WriteLine("Draw line with position: " + line.X1 + "/" + line.Y1 + "/" + line.X2 + "/" + line.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-05-18T05:06:52+00:00Added an answer on May 18, 2026 at 5:06 am

    I was finally able to solve the problem. It seems true that the ScatterViewItem is not yet added to the VisualTree right after the call

    surfaceWindow.ClassScatter.Item.Add(vb);
    

    So I added a SizeChangedEventHandler and a ScatterManipulationDeltaEventHandler to the ScatterViewItem and add the lines there.

    Thanks to Bart, who helped me with this solution

    if (!isExpanded())
    {
        Viewbox vb = new Viewbox();
    
        ClassMetricView metricView = new ClassMetricView();
        metricView.Width = 300;
        metricView.Height = 300;
        metricView.ClassName = this.name;
        metricView.NumberOfMetrics = 5;
        metricView.NumberOfRevisions = 6;
        metricView.MetricsName = new string[] { "LOC", "FanIn", "FanOut", "NOM", "McCabe" };
        int[,] values = { { 10, 10, 10, 10, 10 }, { 20, 20, 20, 20, 20 }, { 30, 30, 30, 30, 30 }, { 40, 40, 40, 40, 40 }, { 50, 50, 50, 50, 50 }, { 60, 60, 60, 60, 60 } };
        metricView.Metrics = values;
        metricView.buildComponent();
        vb.Child = metricView;
        vb.AddHandler(StackPanel.SizeChangedEvent, new System.Windows.SizeChangedEventHandler(SizeChangedHandler));
    
        surfaceWindow.ClassScatter.Items.Add(vb);
    
        ScatterViewItem svItem = _surfaceWindow.ClassScatter.ItemContainerGenerator.ContainerFromItem(vb) as ScatterViewItem;
        svItem.Tag = this.name;
        svItem.AddHandler(ScatterViewItem.ScatterManipulationDeltaEvent, new ScatterManipulationDeltaEventHandler(MovementHandler));
        svItem.AddHandler(StackPanel.SizeChangedEvent, new System.Windows.SizeChangedEventHandler(ScatterSizeChanged));
    
        this.setExpanded(true);
    }
    

    and

    public void MovementHandler(object sender, ScatterManipulationDeltaEventArgs e)
    {
        updateConnectingLines(sender);
    }
    
    public void ScatterSizeChanged(object sender, SizeChangedEventArgs e)
    {
        updateConnectingLines(sender);
    }
    
    private void updateConnectingLines(object sender)
    {
        removeOldLines((sender as ScatterViewItem).Tag as String);
    
        Point childPosition = (sender as ScatterViewItem).TransformToAncestor(_surfaceWindow.ClassScatter).Transform(new Point(0, 0));
        Point parentPosition = _surfaceWindow.RootContainer.TransformToAncestor(_surfaceWindow).Transform(new Point(0, 0));
    
        Line line = new Line();
        line.X1 = parentPosition.X;
        line.Y1 = parentPosition.Y;
        line.X2 = childPosition.X;
        line.Y2 = childPosition.Y;
        line.Stroke = System.Windows.Media.Brushes.Black;
        line.StrokeThickness = 2;
        line.Tag = this.name;
        lines.Add(line);
    
        _surfaceWindow.RootGrid.Children.Add(line);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following method having following line inside it HtmlPage.Window.Invoke(showPopUp,new string[] {Hello from Silverlight});
The following method is launched from the constructor of UserControl. A cross thread exception
The following method does its job but keeps printing a warning also, im pretty
For the following segment of java code, the method of run occurs four times.
The following js method does not return, yet firebug reports no exception: function test_contains_doesNotBailWithoutException()
Noob Question. Stuck on the following code. Getting Default constructor cannot handle exception type
i am using the below json method and following code to parse json method
I have the following code which works just fine when the method is POST,
I am new to Java/threads and I inherited something like the following code. It
I have the following method: protected BigDecimal stringToBigDecimal(String value) throws ParseException { if (Pattern.matches([\\d,.]+,

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.