【问题标题】:How to create a static TabControl in XAML WPF如何在 XAML WPF 中创建静态 TabControl
【发布时间】:2014-01-12 19:07:55
【问题描述】:

我需要在 MainWindow 中创建一个 TabControl,然后我需要在 MainWindow 中创建一个返回该 TabControl 的属性。我不知道如何从另一个窗口访问 TabControl,因为当我这样尝试时,它会显示“需要对象引用 bla bla ...”:

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

我在 MainWindow 中创建的属性是:

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?

此代码返回错误:“需要对象引用...”

【问题讨论】:

  • 发布您的 xaml + 退出代码。

标签: .net wpf tabcontrol


【解决方案1】:

只需在 XAML 中创建 TabControl 并为其命名。您可以在后面的代码中使用该名称:

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

在后面的代码中只使用 MyTabControl。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-29
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    相关资源
    最近更新 更多