Possibility 1:
private void buEliminar_Click(object sender, RoutedEventArgs e)
{
UIElement Hijo = (UIElement)LogicalTreeHelper.FindLogicalNode(Layout, "tbPrueba");
Layout.Children.Remove(Hijo);
}
Details:
http://msdn.microsoft.com/en-us/library/system.windows.logicaltreehelper.findlogicalnode.aspx[
^]
Possibility 2:
TextBlock MyTextBlock = new TextBlock()
{
Name = "tbPrueba",
Text = "Prueba",
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(50, 20, 0, 0),
};
Layout.Children.Add(MyTextBlock);
this.RegisterName("tbPrueba", MyTextBlock);
private void buEliminar_Click(object sender, RoutedEventArgs e)
{
UIElement Hijo = Layout.FindName("tbPrueba") as UIElement;
Layout.Children.Remove(Hijo);
}
There is something written about that:
http://stackoverflow.com/questions/1755377/why-cant-i-access-a-textbox-by-name-with-findname[
^]