在按钮的单击事件后面的代码中创建一个选项卡控件

时间:2009-12-03 06:26:56

标签: c# silverlight

按钮点击事件我必须在按钮下方创建两个标签

private void bnOpen_Click(object sender,RoutedEventArgs e) {

}

2 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

  1. 创建一个TabControl用户控件,其中包含您要显示的所有选项卡。
  2. 在asp.net页面上拖动占位符,例如phTabHolder。
  3. 在按钮单击事件时将用户控件添加到占位符控件,并显示/隐藏要显示的选项卡页面。例如,phTabHolder.Controls.Add(m_UCtlMyTabControl)
  4. 请参阅this for dynamically adding控件。

答案 1 :(得分:0)

我所做的就是:

xaml:

                        主题:ThemeManager.StyleKey = “SelectorDropDownButtonStyle”/>

                    <TextBox x:Name="txtFolderName" Themes:ThemeManager.StyleKey="TextBox"  IsReadOnly="True" Grid.Column="0" />
             </Grid>

    <Controls:TabControl x:Name="tbc" HorizontalAlignment="Stretch" Width="auto" Grid.Row="1" HorizontalContentAlignment="Stretch">
                        <Controls:TabControl.Items >
                            <Controls:TabItem x:Name="brw" Header="Browse" Height="auto">
                    <Grid >
                            <Border x:Name="PopupOuterBorder" Themes:ThemeManager.StyleKey="ReportSelectorOuterBorder"/>
                            <Border x:Name="PopupInnerBorder" Background="#404040" Themes:ThemeManager.StyleKey="ReportSelectorPopupInnerBorder">
                            <ScrollViewer x:Name="scrollBar"   HorizontalScrollBarVisibility="Auto" Height="100" Themes:ThemeManager.StyleKey="TreeScrollViewer" >
                            <Browser:FolderBrowser x:Name="folderPickerTree"   SelectionChanged="tree_SelectionChanged"    ></Browser:FolderBrowser>
                            </ScrollViewer>
                            </Border>
                    </Grid>
            </Controls:TabItem>
            <Controls:TabItem Header="Search" Height="auto" >

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBox x:Name="tbSearch" Grid.Row="0" Grid.Column="0" Themes:ThemeManager.StyleKey="TextBox" TextChanged="SearchTextChangeEvent" />
                    <Button x:Name="bnSearch" Grid.Row="0" Grid.Column="1"  Themes:ThemeManager.StyleKey="Button"  Click="bnSearch_Click" Content="Search"/>
                    <ListBox x:Name="displayfolderList" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="1" Height="30"></ListBox>
                </Grid>
            </Controls:TabItem>
        </Controls:TabControl.Items>       
        </Controls:TabControl>

代码背后:

public FolderPickerControl()         {             的InitializeComponent();             tbc.Visibility = Visibility.Collapsed;         }

private void bnOpen_Click(object sender,RoutedEventArgs e)         {

        if (IsDesignTime)
            return;
        brw.IsSelected = true;    
        if (tbc.Visibility != Visibility.Visible)
        {

            tbc.Visibility = Visibility.Visible;
        }
        else
        {
            tbc.Visibility = Visibility.Collapsed;
        }
    }