Tabitem.focus 仅关注 tabitem 标头

发布于 2024-09-03 12:54:24 字数 464 浏览 12 评论 0原文

嘿。我有一个绑定到可观察集合的选项卡控件。

我尝试过这样做

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稀香 2024-09-10 12:54:24

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.

倾其所爱 2024-09-10 12:54:24

我的解决方案是简单地在 observabletabcollection 上创建一个方法,将 tabcontrol 与 observabletabcollection 关联起来

public TabControl AssociatedTabControl;

internal void BindToTabControl(TabControl TabCtrl)
        {
            AssociatedTabControl = TabCtrl;
        }

,然后在方法调用中进行关联

if (AssociatedTabControl != null) AssociatedTabControl.SelectedItem = tabitem;

My solution became to simply create a method on the observabletabcollection that would associate the tabcontrol with the observabletabcollection

public TabControl AssociatedTabControl;

internal void BindToTabControl(TabControl TabCtrl)
        {
            AssociatedTabControl = TabCtrl;
        }

and then inside a method call

if (AssociatedTabControl != null) AssociatedTabControl.SelectedItem = tabitem;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文