AvalonDock - preventing docking of a panel in a document panel

Is it possible to prevent anchoring to the document panel? I want them to be draggable and move around the screen, but sometimes users drag them to the document panel, which makes them look poor. Then they close the tab, and I cannot reopen the binding.

If this helps my Avalon code below:

<avalonDock:DockingManager.Theme> <avalonDock:VS2010Theme /> </avalonDock:DockingManager.Theme> <avalonDock:DockingManager.DocumentHeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal"> <!-- the TextBlock named Limiter is used to limit the height of the TextBlock for the workflow name. --> <TextBlock x:Name="Limiter" TextWrapping="NoWrap" Visibility="Hidden" TextTrimming="CharacterEllipsis"> L </TextBlock> <TextBlock Text="{Binding Path=Title}" VerticalAlignment="Center" ToolTip="{StaticResource WorkflowTabItemToolTip}" MaxHeight="{Binding ActualHeight, ElementName=Limiter}" MaxWidth="150" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" Margin="0,0,2,0" AutomationProperties.AutomationId="WorkflowTabTitleText"/> <TextBlock Text=" *" ToolTip="Has unsaved changes" Visibility="{Binding Content.UnsavedEdits, Converter={StaticResource BoolToVis}}" AutomationProperties.AutomationId="DirtyTabIndicator"/> </StackPanel> </StackPanel> </DataTemplate> </avalonDock:DockingManager.DocumentHeaderTemplate> <avalonDock:DockingManager.LayoutItemContainerStyleSelector> <utilities1:PanesStyleSelector> <utilities1:PanesStyleSelector.WebUIStyle> <Style TargetType="{x:Type avalonDock:LayoutAnchorableItem}"> <Setter Property="Title" Value="{Binding Model.Title}"/> <Setter Property="IconSource" Value="{Binding Model.IconSource}"/> <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}"/> <Setter Property="ContentId" Value="{Binding Model.ContentId}"/> <Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/> <Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/> </Style> </utilities1:PanesStyleSelector.WebUIStyle> <utilities1:PanesStyleSelector.DocumentStyle> <Style TargetType="{x:Type avalonDock:LayoutItem}"> <Setter Property="Title" Value="{Binding Model.WorkflowName}" /> <Setter Property="IsActive" Value="{Binding Model.IsActive}" /> <Setter Property="IsSelected" Value="{Binding Model.IsActive}" /> </Style> </utilities1:PanesStyleSelector.DocumentStyle> </utilities1:PanesStyleSelector> </avalonDock:DockingManager.LayoutItemContainerStyleSelector> <avalonDock:DockingManager.LayoutItemTemplateSelector> <utilities1:PanesTemplateSelector> <utilities1:PanesTemplateSelector.WorkflowDesignerViewTemplate> <DataTemplate> <ContentControl cal:View.Model="{Binding}" IsTabStop="False" /> </DataTemplate> </utilities1:PanesTemplateSelector.WorkflowDesignerViewTemplate> <utilities1:PanesTemplateSelector.WebUIViewTemplate> <DataTemplate> <ContentControl cal:View.Model="{Binding}" IsTabStop="False" /> </DataTemplate> </utilities1:PanesTemplateSelector.WebUIViewTemplate> </utilities1:PanesTemplateSelector> </avalonDock:DockingManager.LayoutItemTemplateSelector> <avalonDock:LayoutRoot> <avalonDock:LayoutPanel Orientation="Horizontal"> <avalonDock:LayoutDocumentPaneGroup> <avalonDock:LayoutDocumentPane AutomationProperties.AutomationId="AvalonDocumentPane"/> </avalonDock:LayoutDocumentPaneGroup> <avalonDock:LayoutAnchorablePane DockWidth="800" DockMinWidth="400" AutomationProperties.AutomationId="WebUIPane"/> <avalonDock:LayoutAnchorablePane DockWidth="225" DockMinWidth="225" AutomationProperties.AutomationId="ActivitiesPane"> <avalonDock:LayoutAnchorable Title="Activities" AutoHideWidth="225" AutoHideMinWidth="225" CanClose="False" CanHide="False"> <toolbox:ToolboxControl Name="Toolbox" AutomationProperties.AutomationId="ActivitiesToolbox" utilities1:ToolboxItemSource.ToolboxItems="{Binding ToolboxList}" /> </avalonDock:LayoutAnchorable> </avalonDock:LayoutAnchorablePane> </avalonDock:LayoutPanel> </avalonDock:LayoutRoot> </avalonDock:DockingManager> 
+7
c # wpf xaml avalondock
source share
2 answers

Have you tried to catch the event when the binding moves to the window and changed the CanRepositionItems property to false?

0
source share

Although I did not find a direct way to prevent docking, I managed to fix the main problem, namely, to configure various tab headers for tool windows and document windows. My document windows show an asterisk (*) in the tab title to indicate changes (like VS), while tool windows should not.

The solution was to use the DocumentHeaderTemplateSelector and provide it with two different templates: one for documents and tool windows. Here's the XAML:

 <xcad:DockingManager.DocumentHeaderTemplateSelector> <bd:DocumentHeaderTemplateSelector> <bd:DocumentHeaderTemplateSelector.DocumentTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Source="Resources\AppIcon.ico" Margin="0,0,4,0" Width="16" /> <TextBlock Text="{Binding Title}" /> <TextBlock Text=" *" Visibility="{Binding Content.IsDirty, Converter={StaticResource BoolToVisibilityConverter}}" /> </StackPanel> </DataTemplate> </bd:DocumentHeaderTemplateSelector.DocumentTemplate> <bd:DocumentHeaderTemplateSelector.ToolWindowTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Title}" /> </StackPanel> </DataTemplate> </bd:DocumentHeaderTemplateSelector.ToolWindowTemplate> </bd:DocumentHeaderTemplateSelector> </xcad:DockingManager.DocumentHeaderTemplateSelector> 

The selector class is simple:

 Public Class DocumentHeaderTemplateSelector Inherits DataTemplateSelector Public Property DocumentTemplate As DataTemplate Public Property ToolWindowTemplate As DataTemplate Public Overrides Function SelectTemplate(item As Object, container As System.Windows.DependencyObject) As System.Windows.DataTemplate Dim itemAsLayoutContent = TryCast(item, Xceed.Wpf.AvalonDock.Layout.LayoutContent) If TypeOf item Is Xceed.Wpf.AvalonDock.Layout.LayoutDocument AndAlso TypeOf DirectCast(item, Xceed.Wpf.AvalonDock.Layout.LayoutDocument).Content Is DocumentVM Then Return DocumentTemplate Else Return ToolWindowTemplate End If End Function End Class 

Now my tool windows do not show an asterisk (*) and icon, even if they are moved to the document panel.

Hope this helps someone along the way.

0
source share

All Articles