Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JobaDiniz opened this issue Dec 20, 2018 · 1 comment
Open

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

JobaDiniz opened this issue Dec 20, 2018 · 1 comment

Comments

@JobaDiniz
Copy link

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?

@Dirkster99
Copy link

Dirkster99 commented Mar 17, 2019

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants