简体   繁体   English

在WPF(C#)中以编程方式创建TabControl

[英]Create a TabControl programmatically in WPF(C#)

I am a newbie to C# and WPF in particular and I'm wondering how to create a TabControl programatically(not via xaml). 我是C#和WPF的新手,我想知道如何以编程方式(而不是通过xaml)创建TabControl。 I have the following code: 我有以下代码:

private void Button_Click_3(object sender, RoutedEventArgs e)
   {
   TabControl c = new TabControl() 
  }

But the TabControl is not created when the button is clicked. 但是,单击按钮时,不会创建TabControl。 Could someone please give me a basic example on how to create a TabControl programatically. 有人可以给我一个有关如何以编程方式创建TabControl的基本示例。 This may also help me understand how WPF works(I am more used to Swing Java). 这也可能有助于我理解WPF的工作原理(我更习惯于使用Swing Java)。 Many thanks. 非常感谢。

You need to add the TabControl to some part of your window. 您需要将TabControl添加到窗口的某些部分。

Specifically, you should add it to the Children collection of some kind of panel. 具体来说,您应该将其添加到某种面板的Children集合中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM