This is a migrated thread and some comments may be shown as answers.

How to disable compass & rootcompass for certain panes

3 Answers 225 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 21 Nov 2011, 12:35 AM
Hi,

I have a replicated the docking layout that can be found at the very bottom of this page link http://www.telerik.com/help/wpf/raddocking-getting-started2.html .

How can I disable the documenthost items from being dockable in other pane groups other than its own?

I've had a look this following guide http://www.telerik.com/help/wpf/raddocking-how-to-implement-conditional-docking.html , however it works fine if you want to apply the restrictions to all of the panes in the top level docking control, but I only want the restrictions to apply when moving the items from the documenthost container. In short, I don't want any of the documenthost items to be dockable in any other group other than its own original group.

Are there any example of how I can apply restrictions to some pane groups and not to others depending on where the pane in question originated from? I've looked through all of the online documents and forums but I can't seem to find what I'm looking for other than the following:

Private Sub radDocking_PreviewShowCompass(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.Docking.PreviewShowCompassEventArgs)
    e.Compass.IsLeftIndicatorVisible = False
    e.Compass.IsTopIndicatorVisible = False
End Sub

Like I said, this works fine if you want apply to restrictions to all pane groups. I need some way to detect which pane group is displaying the compass so that I can make the decision on which indicators are visible depending on the panel item in question.

Thanks very much for your time, any help will be greatly appreciated,

Rob

3 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 21 Nov 2011, 02:01 AM
ok I think I've found what I'm looking for. In the demos under the docking section there's an example called "Compass Programming" that on the surface looks like it does what I need it to.

I will get to you on this.
0
Robert
Top achievements
Rank 1
answered on 22 Nov 2011, 09:27 PM
Ok, I have this figured out. For those of you who are interested in the code I modified the telerik example to fit in a 'Page' rather than a UserControl and I modified the docking permissions according to my needs.

See below for the XAML and VB code that I am using:

<Page  x:Class="Page1"
        xmlns:telerikDocking="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Docking"
        xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls">
    <Page.Resources>
        <LinearGradientBrush x:Key="OliveBrush" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FFB6CE3B" Offset="1" />
            <GradientStop Color="#FFE1EAB5" />
        </LinearGradientBrush>
  
        <LinearGradientBrush x:Key="BlueBrush" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FF6394CE" Offset="1" />
            <GradientStop Color="#FFC3D6EC" />
        </LinearGradientBrush>
  
        <LinearGradientBrush x:Key="PurpleBrush" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FF987ED3" Offset="1" />
            <GradientStop Color="#FFC4B3E5" />
        </LinearGradientBrush>
    </Page.Resources>
    <Grid>
        <telerikDocking:RadDocking PreviewShowCompass="RadDocking_PreviewShowCompass"   BorderThickness="0" Padding="0" telerikQuickStart:ThemeAwareBackgroundBehavior.IsEnabled="True">
            <telerikDocking:RadDocking.DocumentHost>
  
                <telerikDocking:RadSplitContainer>
                    <telerikDocking:RadPaneGroup>
                        <telerikDocking:RadDocumentPane Header="Document 1" Title="Document 1">
                            <Grid Background="{StaticResource OliveBrush}" />
                        </telerikDocking:RadDocumentPane>
                    </telerikDocking:RadPaneGroup>
                </telerikDocking:RadSplitContainer>
  
            </telerikDocking:RadDocking.DocumentHost>
  
            <telerikDocking:RadSplitContainer Orientation="Vertical" InitialPosition="DockedLeft">
                <telerikDocking:RadPaneGroup>
                    <telerikDocking:RadPane Header="Pane Left 1">
                        <Grid Background="{StaticResource BlueBrush}" />
                    </telerikDocking:RadPane>
                    <telerikDocking:RadPane Header="Pane Left 2">
                        <Grid Background="{StaticResource BlueBrush}" />
                    </telerikDocking:RadPane>
                </telerikDocking:RadPaneGroup>
            </telerikDocking:RadSplitContainer>
  
            <telerikDocking:RadSplitContainer Orientation="Horizontal" InitialPosition="DockedRight">
                <telerikDocking:RadPaneGroup>
                    <telerikDocking:RadPane Header="Pane Right 1">
                        <Grid Background="{StaticResource PurpleBrush}" />
                    </telerikDocking:RadPane>
                </telerikDocking:RadPaneGroup>
                <telerikDocking:RadPaneGroup>
                    <telerikDocking:RadPane Header="Pane Right 2">
                        <Grid Background="{StaticResource PurpleBrush}" />
                    </telerikDocking:RadPane>
                </telerikDocking:RadPaneGroup>
            </telerikDocking:RadSplitContainer>
  
            <telerikDocking:RadSplitContainer Orientation="Horizontal"
                    InitialPosition="DockedBottom">
                <telerikDocking:RadPaneGroup>
                    <telerikDocking:RadPane Header="Pane Bottom 1">
                        <Grid Background="{StaticResource BlueBrush}" />
                    </telerikDocking:RadPane>
                </telerikDocking:RadPaneGroup>
                <telerikDocking:RadPaneGroup>
                    <telerikDocking:RadPane Header="Pane Bottom 2">
                        <Grid Background="{StaticResource OliveBrush}" />
                    </telerikDocking:RadPane>
                </telerikDocking:RadPaneGroup>
            </telerikDocking:RadSplitContainer>
        </telerikDocking:RadDocking>
    </Grid>
  
</Page>

VB code:
Imports System.Windows.Controls
Imports Telerik.Windows.Controls
Imports Telerik.Windows.Controls.Docking
  
  
Class Page1
  
    Private Shared Function CompassNeedsToShow(compass As Telerik.Windows.Controls.Docking.Compass) As Boolean
        Return compass.IsLeftIndicatorVisible OrElse compass.IsTopIndicatorVisible OrElse compass.IsRightIndicatorVisible OrElse compass.IsBottomIndicatorVisible OrElse compass.IsCenterIndicatorVisible
    End Function
  
    Private Enum PaneType
        Olive
        Blue
        Purple
    End Enum
  
  
    Private Sub RadDocking_PreviewShowCompass(sender As Object, e As Telerik.Windows.Controls.Docking.PreviewShowCompassEventArgs)
        If e.TargetGroup IsNot Nothing Then
            e.Compass.IsCenterIndicatorVisible = CanDockIn(e.DraggedSplitContainer, e.TargetGroup, DockPosition.Center)
            e.Compass.IsLeftIndicatorVisible = CanDockIn(e.DraggedSplitContainer, e.TargetGroup, DockPosition.Left)
            e.Compass.IsTopIndicatorVisible = CanDockIn(e.DraggedSplitContainer, e.TargetGroup, DockPosition.Top)
            e.Compass.IsRightIndicatorVisible = CanDockIn(e.DraggedSplitContainer, e.TargetGroup, DockPosition.Right)
            e.Compass.IsBottomIndicatorVisible = CanDockIn(e.DraggedSplitContainer, e.TargetGroup, DockPosition.Bottom)
        Else
            e.Compass.IsLeftIndicatorVisible = CanDock(e.DraggedSplitContainer, DockPosition.Left)
            e.Compass.IsTopIndicatorVisible = CanDock(e.DraggedSplitContainer, DockPosition.Top)
            e.Compass.IsRightIndicatorVisible = CanDock(e.DraggedSplitContainer, DockPosition.Right)
            e.Compass.IsBottomIndicatorVisible = CanDock(e.DraggedSplitContainer, DockPosition.Bottom)
        End If
        e.Canceled = Not (CompassNeedsToShow(e.Compass))
    End Sub
  
    Private Function GetPaneType(pane As RadPane) As PaneType
        Dim c As Panel = TryCast(pane.Content, Panel)
        If c IsNot Nothing Then
            If c.Background.Equals(Me.Resources("OliveBrush")) Then
                Return PaneType.Olive
            ElseIf c.Background.Equals(Me.Resources("BlueBrush")) Then
                Return PaneType.Blue
            Else
                Return PaneType.Purple
            End If
        End If
  
        Return PaneType.Purple
    End Function
  
    Private Function CanDockIn(paneToDock As RadPane, paneInTargetGroup As RadPane, position As DockPosition) As Boolean
        Dim paneToDockType As PaneType = GetPaneType(paneToDock)
        Dim paneInTargetGroupType As PaneType = GetPaneType(paneInTargetGroup)
  
        'PANE DOCK
        Select Case paneToDockType
            Case PaneType.Olive
                Select Case paneInTargetGroupType
  
                    Case PaneType.Olive
                        Return True
                    Case PaneType.Blue
                        Return False
                    Case PaneType.Purple
                        Return False
                End Select
                Exit Select
            Case PaneType.Blue
                Select Case paneInTargetGroupType
  
                    Case PaneType.Olive
                        Return False
                    Case PaneType.Blue
                        Return True
                    Case PaneType.Purple
                        Return position <> DockPosition.Center
                End Select
                Exit Select
            Case PaneType.Purple
                Select Case paneInTargetGroupType
  
                    Case PaneType.Olive
                        Return False
                    Case PaneType.Blue
                        Return position <> DockPosition.Center
                    Case PaneType.Purple
                        Return True
                End Select
                Exit Select
        End Select
  
        Return False
    End Function
  
    'ROOT DOCK
    Private Function CanDock(paneToDock As RadPane, position As DockPosition) As Boolean
        Dim paneToDockType As PaneType = GetPaneType(paneToDock)
  
        Select Case paneToDockType
            Case PaneType.Olive
                Return False
                'Case PaneType.Olive
                '    Return position <> DockPosition.Left
            Case PaneType.Blue
                Return position <> DockPosition.Top
            Case PaneType.Purple
                Return position <> DockPosition.Top
        End Select
  
        Return False
    End Function
  
    Private Function CanDockIn(dragged As ISplitItem, target As ISplitItem, position As DockPosition) As Boolean
        ' If there is a pane that cannot be dropped in any of the targeted panes.
        Return Not dragged.EnumeratePanes().Any(Function(p As RadPane) target.EnumeratePanes().Any(Function(p1 As RadPane) Not CanDockIn(p, p1, position)))
    End Function
  
    Private Function CanDock(dragged As ISplitItem, position As DockPosition) As Boolean
        Return Not dragged.EnumeratePanes().Any(Function(p As RadPane) Not CanDock(p, position))
    End Function
  
End Class


To edit the docking permissions for your requirement search for my code comments 'PANE DOCK' and 'ROOT DOCK'. It's fairly self explanatory.
0
Accepted
Konstantina
Telerik team
answered on 24 Nov 2011, 04:17 PM
Hi Rob,

This is the correct way for achieving this. We are glad that you have resolved the issue without our help.

Regards,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
Docking
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Konstantina
Telerik team
Share this question
or