Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - How to finding the tab a control is on

I'm very new to WPF and don't know how to do this. I have a text box in a tab item on a tab control. How can I programmatically (C#) determine what tab item is the parent of this text box? I would also like to determine what tab control is the parent of the tab item.

Thanks very much.

like image 905
Hosea146 Avatar asked Dec 19 '25 17:12

Hosea146


1 Answers

TabItem.Parent will provide the logical parent element of the TabItem; which will be the associated TabControl. You can use the same approach for any control with the TabItem.

((FrameworkElement)myTextBox.Parent).Parent;

If the item is deeper in the tree and becomes unknown in its depth you will need to begin to approach it in a recursive manner.

like image 116
Aaron McIver Avatar answered Dec 21 '25 08:12

Aaron McIver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!