我之前见过这个。我们需要一个专用的标签项,上面带有“+”符号。像 Silver light Application 中的chrome浏览器一样。
总有一个标签项显示在可见的结尾一半,一旦你点击它,它就会变成一个完整的标签项。
答案 0 :(得分:1)
这有点回答:P
这就是:
创建一个名为LinqToVisualTree的类。您可以在this post的末尾找到它,并解释它的作用。基本上,它允许您通过LINQ查询Visual Tree。
要向TabControl中的选项卡行添加任何内容,您需要操作TabPanel,它包含选项卡的“按钮”。 TabPanel位于System.Windows.Controls.Primitives命名空间中,因此请参阅它。
获取我发现的TabPanel的最简单方法是至少命名一个TabItem并执行此操作:
using System.Windows.Controls.Primitives; // Contains TabPanel
using LinqToVisualTree;
void AddPlusButton() {
// Creates a button beside the tabs
var button = new Button()
{
Content = "+",
IsTabStop = false // To prevent keyboard press
};
// Links the Click with the "new tab" function
button.Click += new RoutedEventHandler(btPlus_Click);
// *** HERE IS THE TRICK ***
// Gets the parent TabPanel in the Visual Tree and cast it
var tabpn = tabItem1.Ancestors<TabPanel>().FirstOrDefault() as TabPanel;
// Links the button created
tabpn.Children.Add(button);
}
以下是加号按钮的方法:
void btPlus_Click(object sender, RoutedEventArgs e)
{
// Creates a new TabItem
var ti = new TabItem();
ti.Header = "TabAdded";
ti.Content = new TextBlock() { Text = "Tab content!" };
// Links it
tabControl.Items.Add(ti);
}
就是这样!提示:我刚刚使用Silverlight Spy了解TabPanel类。在Google上搜索,我可以通过从TabControl更改模板样式来找到执行此操作的方法。
祝你好运!