Tabitem.focus 仅关注 tabitem 标头
嘿。我有一个绑定到可观察集合的选项卡控件。
我尝试过这样做
var tabitem = (TabItem)this.SingleOrDefault(ti => ti.Name == tabname);
tabitem.Focus();
((UserControl)tabitem.Content).Focus();
,它看起来确实专注于 tabitem,但只关注 tabitem 标题中的 btn,而不是内容。 tabitem 内容是另一个用户控件。
如何将焦点更改为内容,以便实际选择选项卡而不仅仅是选项卡标题
我知道 tabcontrol.selecteditem,但我不太确定如何实现它,因为 observablecollection 是实际上是一个我称为 ObservableTabCollection 的类,它只实现了可观察集合。
Hey. I have a tabcontrol that is bound to an observable collection.
I've tried doing
var tabitem = (TabItem)this.SingleOrDefault(ti => ti.Name == tabname);
tabitem.Focus();
((UserControl)tabitem.Content).Focus();
And it does seem like it focuses on the tabitem, but only on a btn in the header of the tabitem, not on the content. the tabitem content is another usercontrol.
How can I change the focus to the content, so that the tab actually is selected and not just the tabheader
I know of tabcontrol.selecteditem, but Iøm not really sure how I would implement this as the observablecollection is actually a class that i've called ObservableTabCollection, that just implements observable collection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
TabControl.SelectedItem
绑定到 ObservableTabCollection 中的特定 TabItem。然后,您可以将绑定设置到从 ObservableTabCollection 中拉出的任何项目,以使该选项卡成为显示的选项卡。Bind
TabControl.SelectedItem
two-way to a specific TabItem from your ObservableTabCollection. Then you can set the binding to any item you pull out of your ObservableTabCollection to make that tab the shown tab.我的解决方案是简单地在 observabletabcollection 上创建一个方法,将 tabcontrol 与 observabletabcollection 关联起来
,然后在方法调用中进行关联
My solution became to simply create a method on the observabletabcollection that would associate the tabcontrol with the observabletabcollection
and then inside a method call