I have one static, and one dynamic set of buttons in two stack panels. I want to get the name of the stack panel of the button clicked. I don't want the type, I want the specific name. Is there a wa开发者_运维技巧y to do that in C#??
Try this:
private ButtonClick(object sender)
{
string parent_name = ((Button)sender).Parent.Name;
}
or for WPF:
private ButtonClick(object sender, RoutedEventArgs e)
{
FrameworkElement parent=(FrameworkElement)((Button)sender).Parent;
string parent_name = parent.Name;
}
精彩评论