private void button_Click(object sender, RoutedEventArgs e)
{
var button = (Button) sender;
var stackPanel = button.Parent as StackPanel;
var childStackPanel = stackPanel.Children.Where(a => a is StackPanel).FirstOrDefault();
// var textbox = childStackPanel.Children.Where(a => a is StackPanel).FirstOrDefault();
}
Not able to get Element within Element, textbox in this case.
But it gives an error when I code chidStackPanel.Children. No Children Property available.
Your
Whereis filtering out Children, which is a collection ofUIElement, which does not have aChildrenproperty. You need to cast it to aStackPaneltoo. But rather than that,OfTypeto the rescue:OfTypefilters out items that are not of that type, while also casting them to that type.