Create a TabControl fom codebehind at a clickevent of a button
on the click event of a button i have to create two tabs below the button
private void bnOpen_Click(object sender, RoutedEventArgs e) {
}
You can do something like following:
phTabHolder.Controls.Add(m_UCtlMyTabControl)
See this for dynamically adding the a control.
What i did is here :
xaml :
Themes: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>
code Behind :
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;
}
}
链接地址: http://www.djcxy.com/p/35696.html
上一篇: 我如何在C#中调用事件方法?