Click here to Skip to main content
15,880,543 members
Articles / Desktop Programming / WPF

WPF Docking Library

Rate me:
Please Sign up or sign in to vote.
4.78/5 (85 votes)
17 Jul 2007CPOL3 min read 1M   24.4K   317  
A WPF library to easily integrate Windows docking features in applications like VS
<custom:Pane x:Class="DockingLibrary.DocumentsPane"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:custom="clr-namespace:DockingLibrary"  >
	<custom:Pane.Resources>
	<Style x:Key="DocTabItemStyle" TargetType="{x:Type TabItem}">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate>
						<Border VerticalAlignment="Bottom" Height="18" BorderThickness="1,1,1,0" CornerRadius="4,4,0,0" x:Name="border" PreviewMouseDown="OnTabItemMouseDown" MouseUp="OnTabItemMouseUp" MouseMove="OnTabItemMouseMove">
							<Border.Background>
								<LinearGradientBrush EndPoint="0.5,0.0" StartPoint="0.5,1">
									<GradientStop Color="{DynamicResource {x:Static SystemColors.ActiveBorderColorKey}}" Offset="0"/>
									<GradientStop Color="#FFFFFFFF" Offset="1"/>
								</LinearGradientBrush>
							</Border.Background>
							<Border.BorderBrush>
								<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.AppWorkspaceColorKey}}"/>
							</Border.BorderBrush>
							<ContentPresenter Content="{TemplateBinding HeaderedContentControl.Header}" Margin="2,0,0,0" x:Name="header"/>
						</Border>
						<ControlTemplate.Triggers>
							<Trigger Property="Selector.IsSelected" Value="True">
								<Setter Property="Background" TargetName="border">
									<Setter.Value>
										<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}"/>
									</Setter.Value>
								</Setter>
								<Setter Property="TextBlock.FontWeight" Value="Bold" TargetName="header"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
   
		<Style x:Key="DocumentsTabSwitchMenuButtonStyle" TargetType="{x:Type Button}">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate>
						<Border Height="18">
							<Path Stretch="Fill" Stroke="#FF000000" StrokeEndLineCap="Square" StrokeLineJoin="Round" StrokeThickness="0" Height="Auto" Data="M3,3 L13,3 L8,15" Margin="3,6,3,3">
								<Path.Fill>
									<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlTextColorKey}}"/>
								</Path.Fill>
							</Path>
						</Border>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>

		<Style x:Key="DocumentsTabCloseButtonStyle" TargetType="{x:Type Button}">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate>
						<Border Height="18" Padding="0,1,0,1">
							<Grid>
								<Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="#FF000000" Margin="3,3,3,3" Data="M0,0L1,1"/>
								<Path Fill="#FFFFFFFF" Stretch="Fill" Stroke="#FF000000" Margin="3,3,3,3" Data="M1,0L0,1"/>
							</Grid>
						</Border>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>

		<ControlTemplate x:Key="DocumentsTabControlTemplate" TargetType="{x:Type TabControl}">
			<Grid x:Name="Grid" KeyboardNavigation.TabNavigation="Local">
				<Grid.ColumnDefinitions>
					<ColumnDefinition x:Name="ColumnDefinition0"/>
					<ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition x:Name="RowDefinition0" Height="Auto"/>
					<RowDefinition x:Name="RowDefinition1" Height="*"/>
				</Grid.RowDefinitions>
				<Border Grid.Row="1" Grid.Column="0" x:Name="ContentPanel" BorderBrush="#FFD0CEBF" BorderThickness="0,0,1,1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local" KeyboardNavigation.DirectionalNavigation="Contained">
					<Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
						<Border Background="{TemplateBinding Background}" x:Name="Border1">
							<ContentPresenter DataContext="{x:Null}" Margin="{TemplateBinding Padding}" x:Name="PART_SelectedContentHost" Content="{TemplateBinding SelectedContent}" ContentTemplate="{TemplateBinding SelectedContentTemplate}" ContentTemplateSelector="{TemplateBinding SelectedContentTemplateSelector}" ContentSource="SelectedContent"/>
						</Border>
					</Border>
				</Border>
				<ScrollViewer x:Name="HeaderPanel" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled">
					<ScrollViewer.Style>
						<Style TargetType="{x:Type ScrollViewer}">
							<Setter Property="Template">
								<Setter.Value>
									<ControlTemplate>
										<Grid Margin="0,0,0,0" Grid.Row="0" Grid.Column="0" x:Name="HeaderPanel">
											<Grid.ColumnDefinitions>
												<ColumnDefinition Width="*"/>
												<ColumnDefinition Width="16"/>
												<ColumnDefinition Width="16"/>
											</Grid.ColumnDefinitions>
											<Grid.RowDefinitions>
												<RowDefinition Height="Auto"/>
											</Grid.RowDefinitions>
											<ScrollContentPresenter Grid.Column="0" Content="{TemplateBinding ScrollViewer.Content}" />
											<Button Grid.Column="1" Style="{StaticResource DocumentsTabSwitchMenuButtonStyle}" PreviewMouseDown="OnBtnDocumentsMenu">
											</Button>
											<Button Grid.Column="2" Style="{StaticResource DocumentsTabCloseButtonStyle}" PreviewMouseDown="OnBtnDocumentClose"/>
										</Grid>
 									</ControlTemplate>
 								</Setter.Value>
 							</Setter>
 						</Style>
 					</ScrollViewer.Style>
 				
					<StackPanel IsItemsHost="True" Orientation="Horizontal" Background="{x:Null}" KeyboardNavigation.TabIndex="1" />
				</ScrollViewer>

    </Grid>
	</ControlTemplate>
	
	</custom:Pane.Resources>
	<Grid>
		<TabControl Name="tbcDocuments" IsSynchronizedWithCurrentItem="True"   Template="{DynamicResource DocumentsTabControlTemplate}" Visibility="Collapsed">
		</TabControl>
	</Grid>
</custom:Pane>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer
Italy Italy
I bought my first computer in Nov 1991, 21st and I started programming with QBasic under MSDOS.
Today my main interest is developping applications with .NET and HTML5 stack.

Comments and Discussions