wpf 中的 Tabitems 问题

Tabitems issues in wpf

我有这个简单的选项卡控件

            <TabControl Margin="0,32,0,0" Background="Aqua">

                <TabItem Header="Dashaboard"
                         FontSize="12"
                         Background="SaddleBrown"
                         Margin="-2,-2,-124,-21">
                    <local:Dashboard Margin="0,0,-8,0"
                                    />

                </TabItem>
                <TabItem Header="Transfer Wizard"
                         Background="LightGray"
                         FontSize="15"
                         ToolTip="Transfering equipments between departments"
                         Margin="123,-2,-224,-21">
                    <local:TransferWizard Margin="0,-4,0,4"
                                          />

                </TabItem>
                <TabItem Header="Addition Wizard"
                         Background="#c8f7c5"
                         ToolTip="Tab for equipment , customer and employees addition"
                         Margin="223,-2,-359,-21">
                    <local:EquipmentAddNavigator Margin="0,-23,0,0" />
                </TabItem>
                <TabItem Header="Addition Wizard"
                         Background="#c8f7c5"
                         ToolTip="Tab for equipment , customer and employees addition"
                         Margin="359,0,-526,-20">
                    <local:EquipmentAddNavigator Margin="0,-23,0,0"
                                                 Loaded="EquipmentAddNavigator_Loaded" />
                </TabItem>


            </TabControl>

我在 Dashboard 中有一个名为 ( refresh() ) 的方法

这是我的问题

1 如何在用户单击仪表板选项卡项时执行刷新方法?

2 如何定义一个全局变量并使其对所有选项卡项都可访问?

像这样处理 Dashboard TabItemSelector.Selected 事件:

<TabItem Header="Dashaboard"
   FontSize="12"
   Background="SaddleBrown"
   Margin="-2,-2,-124,-21"
   Selector.Selected="Dashaboard_Selected">
   <local:Dashboard x:Name="Dashboard" Margin="0,0,-8,0"/>
</TabItem>

在代码中:

private void Dashaboard_Selected(object sender, RoutedEventArgs e)
{
      this.Dashboard.refresh()
}

并在 class 中定义您的全局变量,您的 TabControl 就在其中。 例如,如果您的 TabControlMainWindow.xaml 中,添加一个变量是 MainWindow class,如下所示:

public partial class MainWindow : Window
{
    private variable_type variable_name;
    .
    .
    .
}