WPF - 如何查找控件所在的选项卡
我对 WPF 很陌生,不知道该怎么做。我在选项卡控件的选项卡项中有一个文本框。如何以编程方式 (C#) 确定哪个选项卡项是此文本框的父项?我还想确定哪个选项卡控件是选项卡项的父级。
非常感谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
TabItem.Parent 将提供逻辑父元素
TabItem
的;这将是关联的TabControl
。您可以对带有TabItem
的任何控件使用相同的方法。如果该项目在树中较深并且其深度变得未知,则您将需要开始以递归方式处理它。
TabItem.Parent will provide the logical parent element of the
TabItem
; which will be the associatedTabControl
. You can use the same approach for any control with theTabItem
.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.
您可以使用 FrameworkElement.Parent 向上走WPF 中控件的层次结构。这应该让您(递归地)向上走到找到 TabItem,然后从那里走到 TabControl。
You can use FrameworkElement.Parent to walk up the hierarchy of a control in WPF. This should let you (recursively) walk up until you find the TabItem, then walk up to the TabControl from there.
我也是WPF新手,但是循环搜索呢?
例如:
I am newbie in WPF too, but what about cycle searching?
For example:
以下是查找父控件的通用方法:如何按名称查找 WPF 控件或者输入?
你可以这样称呼它:
Here is a generic method for finding parent controls: How can I find WPF controls by name or type?
You can call it like this: