Get CustomControl from Thumb

时间:2016-10-20 12:54:36

标签: c# wpf templates slider

My question, how do I access an element inside of a Thumb? I made a little designer and created a class derived from the Thumb class.

When I add an element in Canvas, I do it this way:

ConnectableThumb dropThumb = new ConnectableThumb(); //class derived from Thumb
dropThumb.DragDelta += new System.Windows.Controls.Primitives.DragDeltaEventHandler(onDragDelta);
ControlTemplate template = new ControlTemplate();
var fec = new FrameworkElementFactory(typeof(Motor));//my Custom Control
template.VisualTree = fec;
dropThumb.Template = template;
CanvasFenster1.Children.Add(dropThumb);

or in XAML

<local:ConnectableThumb>
        <local:ConnectableThumb.Template>
             <ControlTemplate>
                 <local:ValveSymb x:Name="valve" PreviewMouseLeftButtonDown="valve_PreviewMouseLeftButtonDown" PreviewMouseMove="valve_PreviewMouseMove"></local:ValveSymb>
                  </ControlTemplate>
             </local:ConnectableThumb.Template>
</local:ConnectableThumb>

Each of my CustomControls has an adress the user has to set. What i am trying to do is, search through Children of Canvas and find the Element with a specific adress. My Problem is now that i only get Connectable Thumb as element and i need to access the Element inside this Thumb.

My Code

IEnumerable<ConnectableThumb> canvasElements = CanvasFenster1.Children.OfType<ConnectableThumb>();
foreach (ConnectableThumb element in canvasElements)
            {
                //need to get the Element inside of this ConnectableThumb
            }

I need the element inside this Thumb :D

0 个答案:

没有答案