Example #1
0
        // XXX This won't work for XBAP if in a different window than the main one.
        private void PositionWindow()
        {
            // TODO: Decouple this method from RadWindow class.
            var window = this.Child as RadWindow;

            if (window == null)
            {
                return;
            }

            var rootSize = this.GetRootSize();

            if (rootSize.Width <= 0 || rootSize.Height <= 0)
            {
                ApplicationHelper.RootVisual.LayoutUpdated += this.OnApplicationLayoutUpdated;
                return;
            }

            if (window.ActualWidth <= 0 || window.ActualHeight <= 0)
            {
                window.LayoutUpdated += this.OnWindowLayoutUpdated;
                return;
            }

            if (this.WindowStartupLocation == System.Windows.WindowStartupLocation.CenterOwner &&
                this.Owner != null &&
                (this.Owner.ActualWidth <= 0 || this.Owner.ActualHeight <= 0))
            {
                this.Owner.LayoutUpdated += this.OnWindowOwnerLayoutUpdated;
                return;
            }

            Point parentStart = new Point(window.LeftOffset, window.TopOffset);
            Size  parentSize  = this.GetRootSize();

            if (this.WindowStartupLocation == System.Windows.WindowStartupLocation.CenterOwner &&
                this.Owner != null)
            {
                parentStart = this.Owner
                              .TransformToVisual(ApplicationHelper.RootVisual)
                              .Transform(parentStart);

                parentSize = new Size(this.Owner.ActualWidth, this.Owner.ActualHeight);
            }

            Rect            parentRect = new Rect(parentStart, parentSize);
            PlacementHelper helper     = new PlacementHelper(parentRect,
                                                             new Size(window.ActualWidth, window.ActualHeight),
                                                             0,
                                                             0,
                                                             this.GetRootSize(), window.FlowDirection);

            Point newLocation = helper.GetPlacementOrigin(PlacementMode.Center);

            window.Left = newLocation.X;
            window.Top  = newLocation.Y;
            window.UpdateLayout();
        }
Example #2
0
            private void PositionWindow()
            {
                // TODO: Decouple this method from RadWindow class.
                if (this.radWindow == null)
                {
                    return;
                }

                if (this.radWindow.ActualWidth <= 0 || this.radWindow.ActualHeight <= 0)
                {
                    this.radWindow.LayoutUpdated += this.OnWindowLayoutUpdated;
                    return;
                }

                if (this.WindowStartupLocation == System.Windows.WindowStartupLocation.CenterOwner &&
                    this.Owner != null &&
                    (this.Owner.ActualWidth <= 0 || this.Owner.ActualHeight <= 0))
                {
                    this.Owner.LayoutUpdated += this.OnWindowOwnerLayoutUpdated;
                    return;
                }

                Point parentStart = new Point(this.radWindow.LeftOffset, this.radWindow.TopOffset);
                Size  parentSize  = this.GetRootSize();
                var   radOwner    = this.Owner as RadWindow;
                var   windowOwner = this.Owner as Window;

                if (this.WindowStartupLocation == System.Windows.WindowStartupLocation.CenterOwner)
                {
                    if ((radOwner != null && radOwner.IsOpen) || (windowOwner != null && windowOwner.IsLoaded))
                    {
                        parentStart = this.Owner.PointToScreen(parentStart);

                        parentSize = new Size(this.Owner.ActualWidth, this.Owner.ActualHeight);
                    }
                    else if (radOwner != null || windowOwner != null)
                    {
                        throw new InvalidOperationException("Cannot set Owner property to a RadWindow that has not been shown previously.");
                    }
                }

                parentStart.Offset(-System.Windows.SystemParameters.VirtualScreenLeft, -System.Windows.SystemParameters.VirtualScreenTop);

                Rect            parentRect = new Rect(parentStart, parentSize);
                PlacementHelper helper     = new PlacementHelper(parentRect,
                                                                 new Size(radWindow.ActualWidth, radWindow.ActualHeight),
                                                                 0,
                                                                 0,
                                                                 ApplicationHelper.ApplicationSize, this.radWindow.FlowDirection);

                Point newLocation = helper.GetPlacementOrigin(PlacementMode.Center);

                newLocation.Offset(System.Windows.SystemParameters.VirtualScreenLeft, System.Windows.SystemParameters.VirtualScreenTop);
                radWindow.Left = newLocation.X;
                radWindow.Top  = newLocation.Y;
                radWindow.UpdateLayout();
            }