How to check if window is floating alone or not?

Docking/MDI for WPF Forum

Posted 2 months ago by Yuki
Version: 23.1.4
Avatar

Hello,

Is it possible to check if window is floating alone or not?

I'd like to set ContainerMinSize only when window is floating alone.

Would you please advise how to implement it?

  

The following is sample code.

I don't want to set ContainerMinSize when window is floating but docking with other window...

<sampleBrowser:ProductItemControl
    x:Class="ActiproSoftware.ProductSamples.DockingSamples.QuickStart.LayoutSerialization.MainControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
    xmlns:sampleBrowser="clr-namespace:ActiproSoftware.SampleBrowser"
    xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared">

    <sampleBrowser:ProductItemControl.Resources>

        <!--  Converters  -->
        <shared:ImageConverter x:Key="ImageConverter" />

    </sampleBrowser:ProductItemControl.Resources>

    <sampleBrowser:ProductItemControl.SideBarContent>
        <StackPanel>

            <Expander Style="{StaticResource SampleHeaderDescriptionExpanderStyle}">
                <TextBlock Style="{StaticResource SampleHeaderDescriptionTextBlockStyle}">
                    This QuickStart shows how you can persist the layout of docking windows.
                    Layout data is typically saved when an application is closed and then restored when the application is reopened.
                    Layout data can also be used to restore a default layout.<LineBreak /><LineBreak />
                    In this particular sample, the layout data is maintained in a static member variable.
                    Change the layout by dragging tool windows to other locations.
                    Then switch to another sample and switch back to this sample.
                    You should see the same tool window layout as when you last left the sample.<LineBreak /><LineBreak />
                    By default, only the layout of the tool windows is retained, but this can be changed via a serializer option.
                    By unchecking the Only Save ToolWindow Layout menu item, the entire layout, including documents and the MDI, can be saved and restored.
                    Each docking window also has a CanSerialize property that can be set to false to prevent it from being included in the layout data.<LineBreak /><LineBreak />
                    There are also three Layout menu items that determine how unknown windows in a layout are handled.
                    This situation occurs in this sample when a programmatic tool window is added, then the sample is switched, and reopened.
                    In that scenario, the programmatic tool window isn't known to the DockSite, but it has layout data in the XML.
                    The layout data can be discarded (default), auto-created, or lazy loaded.<LineBreak /><LineBreak />
                    Since the layout data of this sample is saved in a static member variable,
                    changes are not maintained if the entire Sample Browser application is closed.
                    That behavior can easily be updated to save the layout to a file instead.</TextBlock>
            </Expander>

        </StackPanel>
    </sampleBrowser:ProductItemControl.SideBarContent>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!--  DockSite  -->
        <docking:DockSite
            x:Name="dockSite"
            Grid.Row="1"
            CanDocumentWindowsFloat="True"
            CanToolWindowsFloat="True">
            <docking:DockSite.AutoHideLeftContainers>
                <docking:ToolWindowContainer>
                    <docking:ToolWindow
                        x:Name="toolboxToolWindow"
                        Title="Toolbox"
                        ImageSource="/Images/Icons/Toolbox16.png">
                        <TextBlock
                            Margin="5"
                            Text="Place toolbox items here."
                            TextWrapping="Wrap" />
                    </docking:ToolWindow>
                </docking:ToolWindowContainer>
            </docking:DockSite.AutoHideLeftContainers>

            <docking:SplitContainer>

                <!--  Workspace  -->
                <docking:Workspace>
                    <docking:TabbedMdiHost x:Name="tabbedMdiHost">
                        <docking:TabbedMdiContainer>
                            <docking:DocumentWindow
                                Title="Saved Layout XML"
                                CanClose="False"
                                ImageSource="/Images/Icons/TextDocument16.png"
                                SerializationId="LayoutDataDocument">
                                <docking:DocumentWindow.Style>
                                    <Style TargetType="docking:DocumentWindow">
                                        <Style.Triggers>
                                            <Trigger Property="IsFloating" Value="True">
                                                <Setter Property="ContainerMinSize">
                                                    <Setter.Value>
                                                        <Size>
                                                            400
                                                            400
                                                        </Size>
                                                    </Setter.Value>
                                                </Setter>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </docking:DocumentWindow.Style>
                                <TextBox
                                    x:Name="layoutXmlTextBox"
                                    AcceptsReturn="True"
                                    BorderThickness="0"
                                    HorizontalScrollBarVisibility="Auto"
                                    IsReadOnly="True"
                                    VerticalScrollBarVisibility="Auto" />
                            </docking:DocumentWindow>
                        </docking:TabbedMdiContainer>
                    </docking:TabbedMdiHost>
                </docking:Workspace>

                <docking:ToolWindowContainer>
                    <docking:ToolWindow
                        x:Name="solutionExplorerToolWindow"
                        Title="Solution Explorer"
                        ContainerMinSize="200,400"
                        ImageSource="/Images/Icons/SolutionExplorer16.png">
                        <TreeView BorderThickness="0">
                            <TreeViewItem Header="Solution 'Actipro Controls' (1 project)" IsExpanded="True">
                                <TreeViewItem Header="ControlsSample" IsExpanded="True">
                                    <TreeViewItem Header="Properties" />
                                    <TreeViewItem Header="References" />
                                    <TreeViewItem Header="Demo.cs" />
                                </TreeViewItem>
                            </TreeViewItem>
                        </TreeView>
                    </docking:ToolWindow>
                    <docking:ToolWindow
                        x:Name="classViewToolWindow"
                        Title="Class View"
                        ImageSource="/Images/Icons/ClassView16.png">
                        <TreeView BorderThickness="0">
                            <TreeViewItem Header="ControlsSample" IsExpanded="True">
                                <TreeViewItem Header="Project References" />
                                <TreeViewItem Header="ActiproSoftware.ProductSamples.DockingSamples" />
                                <TreeViewItem Header="ActiproSoftware.ProductSamples.EditorsSamples" />
                                <TreeViewItem Header="ActiproSoftware.ProductSamples.SharedSamples" />
                                <TreeViewItem Header="ActiproSoftware.SampleBrowser" />
                                <TreeViewItem Header="XamlGeneratedNamespace" />
                            </TreeViewItem>
                        </TreeView>
                    </docking:ToolWindow>
                    <docking:ToolWindow
                        x:Name="documentOutlineToolWindow"
                        Title="Document Outline"
                        ImageSource="/Images/Icons/DocumentOutline16.png">
                        <TextBox
                            BorderThickness="0"
                            IsReadOnly="True"
                            Text="(not available)"
                            TextWrapping="Wrap" />
                    </docking:ToolWindow>
                </docking:ToolWindowContainer>
            </docking:SplitContainer>

        </docking:DockSite>

        <!--  Menu  -->
        <shared:PixelSnapper>
            <Menu>
                <MenuItem Header="_Layout">
                    <MenuItem
                        x:Name="saveToolWindowLayoutOnlyMenuItem"
                        Click="OnSaveLayoutMenuItemClick"
                        Header="Only Save ToolWindow Layout"
                        IsCheckable="True"
                        IsChecked="True" />
                    <MenuItem
                        Click="OnSaveLayoutMenuItemClick"
                        Header="Can Serialize Class View"
                        IsCheckable="True"
                        IsChecked="{Binding ElementName=classViewToolWindow, Path=CanSerialize, Mode=TwoWay}" />
                    <Separator />
                    <MenuItem
                        x:Name="discardMenuItem"
                        Click="OnWindowDeserializationOptionMenuItemClick"
                        Header="Discard Unknown Windows"
                        IsChecked="True" />
                    <MenuItem
                        x:Name="autoCreateMenuItem"
                        Click="OnWindowDeserializationOptionMenuItemClick"
                        Header="Auto-Create Unknown Windows" />
                    <MenuItem
                        x:Name="lazyLoadMenuItem"
                        Click="OnWindowDeserializationOptionMenuItemClick"
                        Header="Lazy Load Unknown Windows" />
                    <Separator />
                    <MenuItem Click="OnLoadDefaultLayoutMenuItemClick" Header="Reload Default Layout" />
                    <Separator />
                    <MenuItem Click="OnLoadLayoutMenuItemClick" Header="Load Layout" />
                    <MenuItem Click="OnSaveLayoutMenuItemClick" Header="Save Layout" />
                </MenuItem>
                <MenuItem Header="_Activate">
                    <MenuItem
                        x:Name="activeProgrammaticToolWindow1"
                        Click="OnActivateProgrammaticToolWindow1Click"
                        Header="Create Programmatic ToolWindow 1"
                        Icon="{Binding Source='pack://application:,,,/SampleBrowser;component/Images/Icons/Properties16.png', Converter={StaticResource ImageConverter}}" />
                    <MenuItem
                        x:Name="activeProgrammaticToolWindow2"
                        Click="OnActivateProgrammaticToolWindow2Click"
                        Header="Create Programmatic ToolWindow 2"
                        Icon="{Binding Source='pack://application:,,,/SampleBrowser;component/Images/Icons/Properties16.png', Converter={StaticResource ImageConverter}}" />
                    <Separator />
                    <MenuItem
                        Command="{Binding ElementName=classViewToolWindow, Path=ActivateCommand}"
                        Header="Activate Class View"
                        Icon="{Binding Source='pack://application:,,,/SampleBrowser;component/Images/Icons/ClassView16.png', Converter={StaticResource ImageConverter}}" />
                    <MenuItem
                        Command="{Binding ElementName=documentOutlineToolWindow, Path=ActivateCommand}"
                        Header="Activate Document Outline"
                        Icon="{Binding Source='pack://application:,,,/SampleBrowser;component/Images/Icons/DocumentOutline16.png', Converter={StaticResource ImageConverter}}" />
                    <MenuItem
                        Command="{Binding ElementName=solutionExplorerToolWindow, Path=ActivateCommand}"
                        Header="Activate Solution Explorer"
                        Icon="{Binding Source='pack://application:,,,/SampleBrowser;component/Images/Icons/SolutionExplorer16.png', Converter={StaticResource ImageConverter}}" />
                    <MenuItem
                        Command="{Binding ElementName=toolboxToolWindow, Path=ActivateCommand}"
                        Header="Activate Toolbox"
                        Icon="{Binding Source='pack://application:,,,/SampleBrowser;component/Images/Icons/Toolbox16.png', Converter={StaticResource ImageConverter}}" />
                </MenuItem>
            </Menu>
        </shared:PixelSnapper>

    </Grid>

</sampleBrowser:ProductItemControl>

aa

Comments (1)

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

While we don't currently have any direct API for checking if a tool window is floating alone, one option would be to walk up the visual tree and look at controls like ToolWindowContainer, SplitContainer, Workspace, etc. to see if it is alone in a DockSite.

Alternatively, if a tool window is in a single ToolWindowContainer and in a floating DockHost, which you can determine if the DockHost is not the DockSite.PrimaryDockHost, then the WPF Window that contains the DockHost will have its WindowStyle property set to None.  If another tool window is docked next to that tool window in the same DockHost (two or more ToolWindowContainers), or if there is MDI in the DockHost, the WindowStyle will be ThreeDBorderWindow.

But keep in mind that even if you initialize the ContainerMinSize correctly as it initially floats, another tool window could get docked into it later on.


Actipro Software Support

The latest build of this product (v24.1.2) was released 5 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.