Skip to content

How to find out whether the Tool is Docked as a Document? #307

Open

Description

@JobaDiniz

Within my ToolViewModel, how do I know if the tool is docked as a Document? Or if it is floating for example?

I made a tweak in the LayoutInitializer. I've changed PaneLocation enum, adding Floating and Document options:

public void AfterInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableShown)
        {
            // If this is the first anchorable added to this pane, then use the preferred size.
            var tool = anchorableShown.Content as ITool;
            if (tool != null)
            {
                var anchorablePane = anchorableShown.Parent as LayoutAnchorablePane;
                if (anchorablePane != null && anchorablePane.ChildrenCount == 1)
                {
                    switch (tool.PreferredLocation)
                    {
                        case PaneLocation.Left:
                        case PaneLocation.Right:
                            anchorablePane.DockWidth = new GridLength(tool.PreferredWidth, GridUnitType.Pixel);
                            break;
                        case PaneLocation.Bottom:
                            anchorablePane.DockHeight = new GridLength(tool.PreferredHeight, GridUnitType.Pixel);
                            break;
                        case PaneLocation.Floating:
                            {
                                anchorableShown.FloatingHeight = tool.PreferredHeight;
                                anchorableShown.FloatingWidth = tool.PreferredWidth;

                                var window = Application.Current.MainWindow;
                                var screen = System.Windows.Forms.Screen.FromHandle(new WindowInteropHelper(window).Handle);
                                anchorableShown.FloatingTop = (screen.WorkingArea.Height / 2d) - (anchorableShown.FloatingHeight / 2d);
                                anchorableShown.FloatingLeft = (screen.WorkingArea.Width / 2d) - (anchorableShown.FloatingWidth / 2d);
                                anchorableShown.Float();
                                break;
                            }
                        case PaneLocation.Document:
                            anchorableShown.DockAsDocument();
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }

However, MVVM in Avalon is fairly difficult, so I couldn't figure it out how to find out whether my ToolViewModel is docked as document.

Any insights?

Activity

  1. Dirkster99 commented on Mar 17, 2019

    @Dirkster99

    Here is an insight: xceedsoftware/wpftoolkit#1437

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions