在一个按钮的复制过程中创建一个TabControl代码隐藏
在按钮的点击事件中 ,我必须在按钮下方创建两个选项卡
private void bnOpen_Click(object sender,RoutedEventArgs e){
}
你可以做如下的事情:
phTabHolder.Controls.Add(m_UCtlMyTabControl)
看到这个动态添加一个控件。
我做的是这里:
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>
代码背后:
公共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;
}
}
链接地址: http://www.djcxy.com/p/35695.html
上一篇: Create a TabControl fom codebehind at a clickevent of a button
下一篇: How to Save/Overwrite existing Excel file with Excel Interop