如何在 XAML WPF 中创建静态 TabControl [英] How to create a static TabControl in XAML WPF
问题描述
我需要在 MainWindow 中创建一个 TabControl,然后我需要在 MainWindow 中创建一个返回该 TabControl 的属性.我不知道如何从另一个窗口访问 TabControl,因为当我这样尝试时,它说需要一个对象引用 bla bla...":
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");
我在 MainWindow 中创建的属性是:
and the Property I made in MainWindow is:
public TabControl tabcontrol
{ get { return tabc; } set{ tabc = value;} }
值为:
"tabcontrol" is name of Property
"tabc" is name of TabControl that I need in another window
请问,我该怎么做?如何从另一个窗口向 MainWindow 中的 TabControl 添加项目?
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..."
推荐答案
只需在 XAML 中创建 TabControl 并为其命名即可.您可以在后面的代码中使用该名称:
Just create the TabControl in XAML and give it name. Your can use that name in code behind:
<TabControl x:Name="MyTabControl" ... />
在后面的代码中只需使用 MyTabControl.
In code behind just use MyTabControl.
这篇关于如何在 XAML WPF 中创建静态 TabControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!