简体   繁体   中英

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. 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:

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

and the Property I made in MainWindow is:

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?

this code returns error saying : "An object reference is required..."

Just create the TabControl in XAML and give it name. Your can use that name in code behind:

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

In code behind just use MyTabControl.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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