开发者

Getting the "name" of a parent panel from a child control

开发者 https://www.devze.com 2023-04-12 23:22 出处:网络
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开

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;            
}
0

精彩评论

暂无评论...
验证码 换一张
取 消