ControlTemplate findet mit der FindName Methode keine Élemente

lusiphur

Mitglied
Hallo

Ich suche in folgenden Controll Template:
Code:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">


    <ControlTemplate x:Key="Funktion">
        <StackPanel>
            <Image Name="tplImage" Source="/Images/funktion.png" Stretch="Uniform" Width="96" Height="67" HorizontalAlignment="Center"/>
            <TextBlock Name="tplTextBlock" Text="Funktion" HorizontalAlignment="Center"/>
            <TextBox Name="MyFunctionTextBox">Text</TextBox>
            <Label></Label>
        </StackPanel>
    </ControlTemplate>





</ResourceDictionary>

mit dem Aufruf
Code:
ControlTemplate funcTemplate = Application.Current.Resources["Funktion"] as ControlTemplate;

                BasicShape basicShape = designer.AddShape(
                    funcTemplate,
                    e.GetPosition(diagramView));

                TextBox t = (TextBox)funcTemplate.FindName(
                    "MyFunctionTextBox",  // Name des Control
                    basicShape         // Templated Parent also BasicShape
                    );
                t.Text = "Hilfe";
Nach der MyFunctionTextbox doch es kommt immer einer NULL Value Zurück woran könnte das Liegen?

Danke
Luse
Code:
 public BasicShape AddShape(ControlTemplate template, Point position)
        {
            BasicShape shape = new BasicShape();
            shape.Template = template;
            shape.SetPosition(position);
            this.DiagramView.Children.Add(shape);
            return shape;
        }
 
Zurück