WPF Tabcontrol访问框架内的页面

时间:2016-12-12 21:01:35

标签: c# wpf tabs

我有一个Tabcontrol内有框架的页面。

如何在选项卡内框架中加载的页面上的文本框控件中放置文本(比方说,“测试”)?

XAML:

<TabControl Name="tabDynamic" ItemsSource="{Binding}" SelectionChanged="tabDynamic_SelectionChanged" Margin="0,23,0,0">
    <TabControl.Resources>
        <DataTemplate x:Key="TabHeader" DataType="TabItem">
            <DockPanel>
                <Button Name="btnDelete" DockPanel.Dock="Right" Margin="5,0,0,0" Padding="0" Click="btnDelete_Click" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=Name}">
                    <Image Source="Resources/delete.gif" Height="11" Width="11"></Image>
                </Button>
                <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=TabItem }, Path=Header}" />
            </DockPanel>
        </DataTemplate>
    </TabControl.Resources>
</TabControl>

然后加载带有页面的框架:

private TabItem AddTabItem(string TabName)
{
    int count = _tabItems.Count;

    // create new tab item
    TabItem tab = new TabItem();

    tab.Header = TabName;
    tab.Name = string.Format("tab{0}", count);
    tab.HeaderTemplate = tabDynamic.FindResource("TabHeader") as DataTempte;

    tab.MouseDoubleClick += new MouseButtonEventHandler(tab_MouseDoubleClick);

     // add controls to tab item, this case I added just a textbox
    Frame tabFrame = new Frame();
    AMSPage page1 = new AMSPage(TabName);
    tabFrame.Content = page1;
    tab.Content = tabFrame;

    // insert tab item right before the last (+) tab item
    _tabItems.Insert(count - 1, tab);

    return tab;
}

现在我的用户可以在标签之间切换,但我在窗口中有按钮;假设我按下按钮1,并希望将“测试”放在任何页面的文本框中(选定标签)。

0 个答案:

没有答案
相关问题