Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top