Silverlight 4: How to Access Management Created with Codebehind

I am trying to create a method for drawing a line (path) between two UserControls. I found a message from someone that gave me a general pointer on how to do this, I successfully implemented the code and started adapting it to my needs.

I had a problem accessing a user control:

Button b2 = new Button();
var transform2 = b2.TransformToVisual(b2.Parent as UIElement);

It works as it should, but my buttons are created dynamically using the method, so I can’t access them as "b2".

I tried the following:

var transfrom3 = canvas1.Children[0].TransformToVisual(canvas1.Children[0].Parent as UIElement);

but accessing it seems to give me a .Parent error.

If you also tried:

                var p1 = this.FindName(ps.ProcessID.ToString());
                var p2 = this.FindName(ps.PreID.ToString());

                ////get geo data from both controls
                var transform1 = p1.TransformToVisual(p1.Parent as UIElement);
                var transform2 = p2.TransformToVisual(p2.Parent as UIElement);

Can someone tell me how can I access these UserControls?

+3
source share
2 answers

: -

var transfrom3 = canvas1.Children[0].TransformToVisual(canvas1.Children[0].Parent as FrameworkElement);

, UIElement Parent, FrameworkElement, Parent.

(, Name ).

: -

var p1 = this.FindName(ps.ProcessID.ToString());

, , this UserControl, FrameworkElement code: -

canvas1.Children.Add(new Button() {Name = ps.ProcessID.ToString(), Content="Hello"});
0

, , UIElement FrameworkElement, :

                var control1 = this.FindName(ps.ProcessID.ToString()) as FrameworkElement;
                var control2 = this.FindName(ps.PreID.ToString()) as FrameworkElement;
                var transform1 = control1.TransformToVisual(control1.Parent as UIElement);
                var transform2 = control2.TransformToVisual(control2.Parent as UIElement);

var FrameworkElement, .Parent .

!

0

All Articles