简体   繁体   English

如何在XAML WPF中创建静态TabControl

[英]How to create a static TabControl in XAML WPF

I need to create a TabControl in MainWindow, and then I need to make a Property in MainWindow that returns that TabControl. 我需要在MainWindow中创建一个TabControl,然后我需要在MainWindow中创建一个返回该TabControl的Property。 I don't know how to access TabControl from another window because it says "An object reference is required bla bla..." when I try like this: 我不知道如何从另一个窗口访问TabControl,因为当我尝试这样时,它说“对象引用是必需的bla bla ...”:

MainWindow.tabcontrol.Items.Add("tabitem");

and the Property I made in MainWindow is: 我在MainWindow制作的物业是:

public TabControl tabcontrol
{ get { return tabc; } set{ tabc = value;} }

Values are: 价值观是:

"tabcontrol" is name of Property
"tabc" is name of TabControl that I need in another window

Please, how do I do this? 拜托,我该怎么做? How to add items to a TabControl that is in MainWindow from another window? 如何从另一个窗口向MainWindow中的TabControl添加项目?

this code returns error saying : "An object reference is required..." 此代码返回错误说:“需要对象引用...”

Just create the TabControl in XAML and give it name. 只需在XAML中创建TabControl并为其命名即可。 Your can use that name in code behind: 您可以在代码后面使用该名称:

<TabControl x:Name="MyTabControl" ... />

In code behind just use MyTabControl. 在代码后面只使用MyTabControl。

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

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