Friday, May 17, 2024

Preventing the Infragistics XamDockManager splitting panes

We are implementing the Infragistics XamDockManager on an existing application. Among other things the XamDockManager allows the user to split the windows into panes. Each pane shows a page from the application. Here is an example of the XamDockManager after the user has created a vertical split pane.


Our application was not designed to show such narrow pages so, like the application above, it doesn't "squish" well. One option we are considering is disabling this feature, which would mean users can only group or float windows. The users have two options for creating a split pane. They can drag onto a button or they can use the pane header's context menu.



To prevent the user from creating split panes we need to suppress both these options. Let's start with an application that allows split panes.

Start a new Visual Basic WPF application using Framework. That's the way I'm swinging today. Call it NoSplitPanes. Add references to XamDockManager and Infragistics.


Modify the MainWindow XAML to look like this

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:NoSplitPanes"
        xmlns:igDock="http://infragistics.com/DockManager"
        mc:Ignorable="d"
        Title="No Split Panes" Height="450" Width="800">
    <igDock:XamDockManager Grid.Row="1" Grid.Column="2"
                            TabItemDragBehavior="DisplayInsertionBar"
                            UnpinnedTabHoverAction="Flyout"
                            AllowMaximizeFloatingWindows="True"
                            AllowMinimizeFloatingWindows="True"
                            ShowFloatingWindowsInTaskbar="True">
        <igDock:DocumentContentHost  >
            <igDock:SplitPane  >
                <igDock:TabGroupPane>
                    <igDock:ContentPane Header="You Can't split me">You can group us and float us, but you can't split us or pin us</igDock:ContentPane>
                    <igDock:ContentPane Header="Can't pin me either">You can't pin us because you have to split us before you can pin us</igDock:ContentPane>
                </igDock:TabGroupPane>
            </igDock:SplitPane>
        </igDock:DocumentContentHost>
    </igDock:XamDockManager>
</Window>

You can hide the buttons by styling them away. Add this style to the XamDockManager.

        <igDock:XamDockManager.Resources>
            <Style TargetType="igDock:DockedPaneSplitter">
                <Setter Property="IsEnabled" Value="False"/>
            </Style>
            <Style TargetType="igDock:SplitPaneSplitter">
                <Setter Property="IsEnabled" Value="False"/>
            </Style>
            <Style TargetType="igDock:DockingIndicator">
                <Style.Triggers>
                    <Trigger Property="Position" Value="Top">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </Trigger>
                    <Trigger Property="Position" Value="Bottom">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </Trigger>
                    <Trigger Property="Position" Value="Left">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </Trigger>
                    <Trigger Property="Position" Value="Right">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </Trigger>
                    <Trigger Property="Position" Value="Center">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </igDock:XamDockManager.Resources>

You can disabled the context menu items by writing am OptionsMenuOpening event handler. Start by added the event to a new style.

            <Style TargetType="igDock:ContentPane">
                <EventSetter Event="OptionsMenuOpening" Handler="ContentPane_DisableNewTabGroup"/>
            </Style>

The event handler goes in the code behind and suppresses menu items based on their header. It's a bit of a kludge.

Imports Infragistics.Windows.DockManager.Events

Class MainWindow
    Private Sub ContentPane_DisableNewTabGroup(sender As Object, e As PaneOptionsMenuOpeningEventArgs)
        For Each item As MenuItem In e.Items.OfType(Of MenuItem).Where(Function(i) i.Header IsNot Nothing)
            If item.Header.ToString().Contains("Tab Group") Then    ' Fine tune this to disable whatever you want
                item.IsEnabled = False
            End If
        Next
    End Sub

End Class

Now when you drag a pane the docking buttons are hidden and the context menu has the new Tab Group options disabled.




No comments:

Post a Comment