本文介绍了在选项卡控件中搜索基于字符串值的特定选项卡项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在名称与特定字符串值匹配的 tabControl 中选择 tabItem .我猜我将不得不进行某种搜索.

I would like to know how to select a tabItem in a tabControl whose name matches a specific string value. I'm guessing that I will have to do some sort of search.

这是一个视觉示例:

string selectedTabItem = "TabItem";

//if there exists a Tab Item in this specific tab control
//with the above string as it's Name
//that Tab Item .IsSelected = true;

推荐答案

假设您是手动创建标签页,而不是通过绑定创建标签,那么这应该可行:

Assuming that you create your tabs manually, and not via bindings, then this should work:

tabControl.SelectedItem = tabControl.Items.OfType<TabItem>().SingleOrDefault(n => n.Name == selectedTabItem);

这篇关于在选项卡控件中搜索基于字符串值的特定选项卡项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 13:03