How to create a static TabControl in XAML WPF

时光毁灭记忆、已成空白 提交于 2019-12-11 19:11:40

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/21073869/how-to-create-a-static-tabcontrol-in-xaml-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!