Example #1
0
        private void FindAppropriateViewHost(IViewFactory factory, ViewBase view)
        {
            var host = Grid.RootHost;

            if (!factory.IsSingleton)
            {
                foreach (var v in factory.CreatedViews)
                {
                    if (v.Host != null && v.Host.IsDocumentWell)
                    {
                        host = v.Host;
                    }
                }
                host.AddView(view);
            }
            else
            {
                switch (factory.DefaultViewPosition)
                {
                case ViewPosition.SecondaryDocumentHost:
                    lock (ViewHost.ViewHosts)
                    {
                        foreach (var h in ViewHost.ViewHosts)
                        {
                            if (h != host && h.IsDocumentWell)
                            {
                                h.AddView(view);
                                return;
                            }
                        }
                    }
                    host = new ViewHost(Grid, false, true, new[] { view })
                    {
                        Size = Grid.RootHost.Size
                    };
                    Grid.RootHost.PerformDock(host, DockResult.Right);
                    break;

                case ViewPosition.Left:
                    host = new ViewHost(Grid, false, false, new[] { view });
                    Grid.PerformDock(host, DockResult.Left);
                    break;

                case ViewPosition.Top:
                    host = new ViewHost(Grid, false, false, new[] { view });
                    Grid.PerformDock(host, DockResult.Top);
                    break;

                case ViewPosition.Right:
                    host = new ViewHost(Grid, false, false, new[] { view });
                    Grid.PerformDock(host, DockResult.Right);
                    break;

                case ViewPosition.Bottom:
                    host = new ViewHost(Grid, false, false, new[] { view });
                    Grid.PerformDock(host, DockResult.Bottom);
                    break;

                case ViewPosition.LeftAutoHide:
                    host = new ViewHost(Grid, false, false, new[] { view });
                    host.UnpinFromLeft();
                    break;

                case ViewPosition.TopAutoHide:
                    host = new ViewHost(Grid, false, false, new[] { view });
                    host.UnpinFromTop();
                    break;

                case ViewPosition.RightAutoHide:
                    host = new ViewHost(Grid, false, false, new[] { view });
                    host.UnpinFromRight();
                    break;

                case ViewPosition.BottomAutoHide:
                    host = new ViewHost(Grid, false, false, new[] { view });
                    host.UnpinFromBottom();
                    break;

                case ViewPosition.Float:
                    host = new ViewHost(Grid, false, false, new[] { view });
                    var form = host.PrepareFloatingMode();
                    form.Location = Grid.PointToScreen(new Point(20, 20));
                    form.Show(Grid.TopLevelControl);
                    break;

                default:
                    Grid.RootHost.AddView(view);
                    break;
                }
            }
        }