Пример #1
0
        /// <summary>
        /// The default constructor
        /// </summary>
        ///
        public WindowViewModel(Window window)
        {
            ChangePage(ApplicationPage.Login);

            this.window          = window;
            window.StateChanged += (sender, e) =>
            {
                // Fire off events for all properties that are affected by a resize
                WindowResized();
            };

            // Fix window resize issue
            var resizer = new WindowResizer(window);

            // Listen out for dock changes
            resizer.WindowDockChanged += (dock) =>
            {
                // Store last position
                dockPosition = dock;
                // Fire off resize events
                WindowResized();
            };

            // Create commands
            MinimizeCommand = new RelayCommand(() => window.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => window.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => window.Close());
        }
Пример #2
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="window"></param>
        public WindowViewModel(Window window)
        {
            _mWindow = window;

            //Listen out for the window resizing
            _mWindow.StateChanged += (Sender, e) =>
            {
                // Fire off events for all properties that are affected by a resize
                WindowResized();
            };

            MinimizeCmd = new RelayCommand(action => { _mWindow.WindowState = WindowState.Minimized; });
            MaximizeCmd = new RelayCommand(action => { _mWindow.WindowState ^= WindowState.Maximized; });
            CloseCmd    = new RelayCommand(action => { _mWindow.Close(); });
            MenuCmd     = new RelayCommand(action => { SystemCommands.ShowSystemMenu(_mWindow, GetMousePosition()); });


            // Fix window resize issue
            var resizer = new WindowResizer(_mWindow);

            resizer.WindowDockChanged += (dock) =>
            {
                _mDockPosition = dock;

                WindowResized();
            };
        }
Пример #3
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public WindowViewModel(System.Windows.Window window)
        {
            mWindow = window;

            // Listen out for the window resizing
            mWindow.StateChanged += (sender, e) =>
            {
                // Fire off events for all properties that are affected by a resize
                OnPropertyChanged(nameof(ResizeBorderThickness));
                OnPropertyChanged(nameof(OuterMarginSize));
                OnPropertyChanged(nameof(OuterMarginSizeThickness));
                OnPropertyChanged(nameof(WindowRadius));
                OnPropertyChanged(nameof(WindowCornerRadius));
            };

            // Create commands
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => mWindow.Close());
            MenuCommand     = new RelayCommand(() => SystemCommands.ShowSystemMenu(mWindow, GetMousePosition()));

            // Fix window resize issue
            var resizer = new WindowResizer(mWindow);

            resizer.WindowDockChanged += (dock) => { mDockPosition = dock; };
        }
Пример #4
0
        public WindowViewModel(Window window, bool isModal = false)
        {
            mWindow = window;

            // Listen out for the window resizing
            mWindow.StateChanged += (sender, e) =>
            {
                // Fire off events for all properties that are affected by a resize
                WindowResized();
            };

            // Create commands
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            if (isModal == false)
            {
                CloseCommand = new RelayCommand(() => mWindow.Visibility = System.Windows.Visibility.Hidden);
            }
            else
            {
                CloseCommand = new RelayCommand(() => mWindow.Close());
            }

            // Fix window resize issue
            var resizer = new WindowResizer(mWindow);

            // Listen out for dock changes
            resizer.WindowDockChanged += (dock) =>
            {
                // Store last position
                mDockPosition = dock;
                // Fire off resize events
                WindowResized();
            };
        }
Пример #5
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="window"></param>
        public WindowViewModel(Window window)
        {
            mWindow = window;
            mWindow.StateChanged += (sender, e) => {
                WindowResized();
            };

            // Opravuje bug při zvětšovaní okna
            var WinRes = new WindowResizer(mWindow);

            // Listen out for dock changes
            WinRes.WindowDockChanged += (dock) =>
            {
                // Store last position
                mDockPosition = dock;

                // Fire off resize events
                WindowResized();
            };

            // Inicilaizace příkazů
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => mWindow.Close());
            MenuCommand     = new RelayCommand(() => OpenMenu());
        }
Пример #6
0
        public WindowViewModel(Window window)
        {
            this.window = window;

            // Listen for window resizing
            window.StateChanged += (sender, e) => {
                WindowResized();
            };
            window.Closed += (sender, e) => {
                window.Close();
            };

            // Create Commands
            MinimizeCommand = new RelayCommand(() => window.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => window.WindowState = window.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => window.Close());
            MenuCommand     = new RelayCommand(() => SystemCommands.ShowSystemMenu(window, GetMousePosition()));

            // Fix window resize issue
            var resizer = new WindowResizer(window);

            // Listen for dock changes
            resizer.WindowDockChanged += (dock) => {
                dockPosition = dock;
                // Call resize events
                WindowResized();
            };
        }
Пример #7
0
        /// <summary>
        /// 기본 생성자
        /// </summary>
        /// <param name="window"></param>

        public WindowViewModel(Window window)
        {
            mWindow = window;

            mWindow.StateChanged += (sender, e) =>
            {
                OnPropertyChanged(nameof(ResizeBorderThickness));
                OnPropertyChanged(nameof(OuterMarginSize));
                OnPropertyChanged(nameof(OuterMarginSizeThickness));
                OnPropertyChanged(nameof(WindowRadius));
                OnPropertyChanged(nameof(WindowCornerRadius));
            };

            //Create Commands
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => mWindow.Close());
            MenuCommand     = new RelayCommand(() => SystemCommands.ShowSystemMenu(mWindow, GetMousePosition()));

            var resizer = new WindowResizer(mWindow);

            // Listen out for dock changes
            resizer.WindowDockChanged += (dock) =>
            {
                // Store last position
                mDockPosition = dock;

                // Fire off resize events
                WindowResized();
            };
        }
        public MainWindowViewModel(Window window)
        {
            mWindow = window;

            // Listen out for the window resizing
            mWindow.StateChanged += (sender, e) =>
            {
                WindowResized();
            };

            MinimizeCommand = new RelayCommand((arg) => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand((arg) => mWindow.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand((arg) => mWindow.Close());
            MenuCommand     = new RelayCommand((arg) => SystemCommands.ShowSystemMenu(mWindow, GetMousePosition()));

            // Fix window resize issue
            mWindowResizer = new WindowResizer(mWindow);

            // Listen out for dock changes
            mWindowResizer.WindowDockChanged += (dock) =>
            {
                // Store last position
                mDockPosition = dock;

                // Fire off resize events
                WindowResized();
            };
        }
Пример #9
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public WindowViewModel(Window window)
        {
            mWindow = window;

            // Listen out for the window resizing
            mWindow.StateChanged += (sender, e) =>
            {
                // Fire off events for all properties that are affected by a resize
                WindowResized();
            };

            // Create commands
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => mWindow.Close());
            MenuCommand     = new RelayCommand(() => SystemCommands.ShowSystemMenu(mWindow, GetMousePosition()));

            // Fix window resize issue
            var resizer = new WindowResizer(mWindow);

            // Listen out for dock changes
            resizer.WindowDockChanged += (dock) =>
            {
                // Store last position
                mDockPosition = dock;

                // Fire off resize events
                WindowResized();
            };
        }
Пример #10
0
        /// <summary>
        /// Monitors for size changes and detects if the window has been docked (Aero snap) to an edge
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            // We cannot find positioning until the window transform has been established
            if (mTransformToDevice == default(Matrix) ||
                mWindow is null)
            {
                return;
            }

            // Get the WPF size
            var size = e.NewSize;

            // Get window rectangle
            var top    = mWindow.Top;
            var left   = mWindow.Left;
            var bottom = top + size.Height;
            var right  = left + mWindow.Width;

            // Get window position/size in device pixels
            var windowTopLeft     = mTransformToDevice.Transform(new Point(left, top));
            var windowBottomRight = mTransformToDevice.Transform(new Point(right, bottom));

            // Check for edges docked
            var edgedTop    = windowTopLeft.Y <= (mScreenSize.Top + mEdgeTolerance);
            var edgedLeft   = windowTopLeft.X <= (mScreenSize.Left + mEdgeTolerance);
            var edgedBottom = windowBottomRight.Y >= (mScreenSize.Bottom - mEdgeTolerance);
            var edgedRight  = windowBottomRight.X >= (mScreenSize.Right - mEdgeTolerance);

            // Get docked position
            var dock = WindowDockPosition.Undocked;

            // Left docking
            if (edgedTop && edgedBottom && edgedLeft)
            {
                dock = WindowDockPosition.Left;
            }
            else if (edgedTop && edgedBottom && edgedRight)
            {
                dock = WindowDockPosition.Right;
            }
            // None
            else
            {
                dock = WindowDockPosition.Undocked;
            }

            // If dock has changed
            if (dock != mLastDock)
            {
                // Inform listeners
                WindowDockChanged(dock);
            }

            // Save last dock position
            mLastDock = dock;
        }
Пример #11
0
        /// <summary>
        /// Monitors for size changes and detects if the window has been docked (Aero snap) to an edge
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            // Cannot calculate size until we know monitor scale
            if (mMonitorDpi == null)
            {
                return;
            }

            // Get the WPF size
            var size = e.NewSize;

            // Get window rectangle
            var top    = mWindow.Top;
            var left   = mWindow.Left;
            var bottom = top + size.Height;
            var right  = left + mWindow.Width;

            // Get window position/size in device pixels
            var windowTopLeft     = new Point(left * mMonitorDpi.Value.DpiScaleX, top * mMonitorDpi.Value.DpiScaleX);
            var windowBottomRight = new Point(right * mMonitorDpi.Value.DpiScaleX, bottom * mMonitorDpi.Value.DpiScaleX);

            // Check for edges docked
            var edgedTop    = windowTopLeft.Y <= (mScreenSize.Top + mEdgeTolerance);
            var edgedLeft   = windowTopLeft.X <= (mScreenSize.Left + mEdgeTolerance);
            var edgedBottom = windowBottomRight.Y >= (mScreenSize.Bottom - mEdgeTolerance);
            var edgedRight  = windowBottomRight.X >= (mScreenSize.Right - mEdgeTolerance);

            // Get docked position
            var dock = WindowDockPosition.Undocked;

            // Left docking
            if (edgedTop && edgedBottom && edgedLeft)
            {
                dock = WindowDockPosition.Left;
            }
            else if (edgedTop && edgedBottom && edgedRight)
            {
                dock = WindowDockPosition.Right;
            }
            // None
            else
            {
                dock = WindowDockPosition.Undocked;
            }

            // If dock has changed
            if (dock != mLastDock)
            {
                // Inform listeners
                WindowDockChanged(dock);
            }

            // Save last dock position
            mLastDock = dock;
        }
Пример #12
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public WindowViewModel(Window window)
        {
            _window = window;

            _window.StateChanged += (sender, e) => WindowResized();

            // Fix window resize issue
            _windowResizer = new WindowResizer(_window);

            _windowResizer.WindowDockChanged += (dock) =>
            {
                _dockPosition = dock;

                WindowResized();
            };
        }
Пример #13
0
        private void FixerOnWindowDockChanged(WindowDockPosition dockPosition)
        {
            switch (dockPosition)
            {
            case WindowDockPosition.Undocked:
                if (AssociatedObject.WindowState != WindowState.Maximized)
                {
                    AssociatedObject.Margin = new Thickness(10);
                }
                break;

            default:
                AssociatedObject.Margin = new Thickness(0);
                break;
            }
        }
Пример #14
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="window"></param>
        public WindowViewModel(Window window)
        {
            mWindow = window;

            // Listen out for the window resizing
            mWindow.StateChanged += (sender, e) =>
            {
                // Fire off events for all properties that are affected by a resize
                WindowResized();
            };

            // Create commands
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => mWindow.Close());
            MenuCommand     = new RelayCommand(() => SystemCommands.ShowSystemMenu(mWindow, GetMousePosition()));
            // Got to orders page
            OrdersPanelCommand = new RelayCommand(() => IoC.Get <ApplicationViewModel>().GoToPage(ApplicationPage.Orders));
            // Got to customers page
            CustomersCommand = new RelayCommand(() => IoC.Get <ApplicationViewModel>().GoToPage(ApplicationPage.Customers));
            // Got to settings page
            SettingsCommand = new RelayCommand(() => IoC.Get <ApplicationViewModel>().GoToPage(ApplicationPage.Settings));

            // Fix window resize issue
            var resizer = new WindowResizer(mWindow);

            // Listen out for dock changes
            resizer.WindowDockChanged += (dock) =>
            {
                // Store last position
                mDockPosition = dock;

                // Fire off resize events
                WindowResized();
            };

            // Get the current version of our app
            Assembly        assembly    = Assembly.GetExecutingAssembly();
            FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);

            CurrentVersion = $" v{ versionInfo.FileVersion }";

            #if !DEBUG
            // Check for updates
            CheckForUpdates();
            #endif
        }
Пример #15
0
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (mTransformToDevice == default(Matrix))
            {
                return;
            }

            var size = e.NewSize;

            var top    = mWindow.Top;
            var left   = mWindow.Left;
            var bottom = top + size.Height;
            var right  = left + mWindow.Width;

            var windowTopLeft     = mTransformToDevice.Transform(new Point(left, top));
            var windowBottomRight = mTransformToDevice.Transform(new Point(right, bottom));

            var edgedTop    = windowTopLeft.Y <= (mScreenSize.Top + mEdgeTolerance);
            var edgedLeft   = windowTopLeft.X <= (mScreenSize.Left + mEdgeTolerance);
            var edgedBottom = windowBottomRight.Y >= (mScreenSize.Bottom - mEdgeTolerance);
            var edgedRight  = windowBottomRight.X >= (mScreenSize.Right - mEdgeTolerance);

            var dock = WindowDockPosition.Undocked;

            if (edgedTop && edgedBottom && edgedLeft)
            {
                dock = WindowDockPosition.Left;
            }
            else if (edgedTop && edgedBottom && edgedRight)
            {
                dock = WindowDockPosition.Right;
            }

            else
            {
                dock = WindowDockPosition.Undocked;
            }

            if (dock != mLastDock)
            {
                WindowDockChanged(dock);
            }

            mLastDock = dock;
        }
Пример #16
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        public WindowViewModel(Window window)
        {
            mWindow = window;

            mWindow.StateChanged += (sender, e) =>
            {
                WindowResized();
            };

            // Creating the title bar commands
            MinimizeCommand   = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand   = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            CloseCommand      = new RelayCommand(() => mWindow.Close());
            SystemMenuCommand = new RelayCommand(() => SystemCommands.ShowSystemMenu(mWindow, GetMousePosition()));

            // Call window resizer
            mWindowResizer = new WindowResizer(mWindow);

            mWindowResizer.WindowDockChanged += (dock) =>
            {
                mDockPosition = dock;

                WindowResized();
            };

            // On window being moved/dragged
            mWindowResizer.WindowStartedMove += () => { BeingMoved = true; };

            // Fix dropping an undocked window at top which should be positioned at the
            // very top of screen
            mWindowResizer.WindowFinishedMove += () =>
            {
                // Update being moved flag
                BeingMoved = false;

                // Check for moved to top of window and not at an edge...
                if (mDockPosition == WindowDockPosition.Undocked && mWindow.Top == mWindowResizer.CurrentScreenSize.Top)
                {
                    // if so, move it to the true top ( the border size )
                    mWindow.Top = -OuterMarginThickness.Top;
                }
            };
        }
Пример #17
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public WindowViewModel(Window window)
        {
            mWindow = window;

            // Listen out for the window resizing
            mWindow.StateChanged += (sender, e) =>
            {
                // Fire off events for all properties that are affected by a resize
                WindowResized();
            };

            // Create commands
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => mWindow.Close());
            MenuCommand     = new RelayCommand(() => SystemCommands.ShowSystemMenu(mWindow, GetMousePosition()));

            // Fix window resize issue
            mWindowResizer = new WindowResizer(mWindow);

            // Listen out for dock changes
            mWindowResizer.WindowDockChanged += (dock) =>
            {
                // Store last position
                mDockPosition = dock;

                // Fire off resize events
                WindowResized();
            };

            TokenHelper tg    = new TokenHelper();
            var         token = tg.ReadTokenFromDisk();

            if (token != null)
            {
                this.CurrentPage = ApplicationPage.Server;
            }
            else
            {
                this.CurrentPage = ApplicationPage.Login;
            }
        }
Пример #18
0
        public WindowViewModel(Window window)
        {
            this.window = window;

            this.window.StateChanged += (sender, e) =>
            {
                this.WindowResized();
            };

            this.MinimizeCommand = new RelayCommand(() => this.window.WindowState = WindowState.Minimized);
            this.MaximizeCommand = new RelayCommand(() => this.window.WindowState ^= WindowState.Maximized);
            this.CloseCommand    = new RelayCommand(() => this.window.Close());

            resizer = new WindowResizer(window);
            resizer.WindowDockChanged += (dock) =>
            {
                this.dockPosition = dock;

                this.WindowResized();
            };
        }
Пример #19
0
        public WindowViewModel(Window window)
        {
            this.window = window;

            window.StateChanged += (sender, e) =>
            {
                WindowResized();
            };

            MinimizeCommand = new RelayCommand(() => window.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => window.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => window.Close());
            MenuCommand     = new RelayCommand(() => SystemCommands.ShowSystemMenu(window, getMousePosition()));

            var resizer = new WindowResizer(window);

            resizer.WindowDockChanged += (dock) =>
            {
                dockPosition = dock;
                WindowResized();
            };
        }
Пример #20
0
        public MainWindowViewModel(Window window)
        {
            mWindow = window;

            mWindow.StateChanged += (sender, e) =>
            {
                mWindowStateChanged();
            };

            CloseCommand    = new RelayCommand(() => mWindow.Close());
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            SystemCommand   = new RelayCommand(() => SystemCommands.ShowSystemMenu(mWindow, mWindow.PointToScreen(Mouse.GetPosition(mWindow))));

            var resizer = new WindowResizer(mWindow);

            resizer.WindowDockChanged += (dock) =>
            {
                mDockPosition = dock;
                mWindowStateChanged();
            };
        }
Пример #21
0
        /// <summary>
        /// Monitors for size changes and detects if the window has been docked (Aero snap) to an edge
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            // Make sure our monitor info is up-to-date
            WmGetMinMaxInfo(IntPtr.Zero, IntPtr.Zero);

            // Get the monitor transform for the current position
            mMonitorDpi = VisualTreeHelper.GetDpi(mWindow);

            // Cannot calculate size until we know monitor scale
            if (mMonitorDpi == null)
            {
                return;
            }

            // Get window rectangle
            var top    = mWindow.Top;
            var left   = mWindow.Left;
            var bottom = top + mWindow.Height;
            var right  = left + mWindow.Width;

            // Get window position/size in device pixels
            var windowTopLeft     = new Point(left * mMonitorDpi.Value.DpiScaleX, top * mMonitorDpi.Value.DpiScaleX);
            var windowBottomRight = new Point(right * mMonitorDpi.Value.DpiScaleX, bottom * mMonitorDpi.Value.DpiScaleX);

            // Check for edges docked
            var edgedTop    = windowTopLeft.Y <= (mScreenSize.Top + mEdgeTolerance) && windowTopLeft.Y >= (mScreenSize.Top - mEdgeTolerance);
            var edgedLeft   = windowTopLeft.X <= (mScreenSize.Left + mEdgeTolerance) && windowTopLeft.X >= (mScreenSize.Left - mEdgeTolerance);
            var edgedBottom = windowBottomRight.Y >= (mScreenSize.Bottom - mEdgeTolerance) && windowBottomRight.Y <= (mScreenSize.Bottom + mEdgeTolerance);
            var edgedRight  = windowBottomRight.X >= (mScreenSize.Right - mEdgeTolerance) && windowBottomRight.X <= (mScreenSize.Right + mEdgeTolerance);

            // Get docked position
            var dock = WindowDockPosition.Undocked;

            // Left docking
            if (edgedTop && edgedBottom && edgedLeft)
            {
                dock = WindowDockPosition.Left;
            }
            // Right docking
            else if (edgedTop && edgedBottom && edgedRight)
            {
                dock = WindowDockPosition.Right;
            }
            // Top/bottom
            else if (edgedTop && edgedBottom)
            {
                dock = WindowDockPosition.TopBottom;
            }
            // Top-left
            else if (edgedTop && edgedLeft)
            {
                dock = WindowDockPosition.TopLeft;
            }
            // Top-right
            else if (edgedTop && edgedRight)
            {
                dock = WindowDockPosition.TopRight;
            }
            // Bottom-left
            else if (edgedBottom && edgedLeft)
            {
                dock = WindowDockPosition.BottomLeft;
            }
            // Bottom-right
            else if (edgedBottom && edgedRight)
            {
                dock = WindowDockPosition.BottomRight;
            }

            // None
            else
            {
                dock = WindowDockPosition.Undocked;
            }

            // If dock has changed
            if (dock != mLastDock)
            {
                // Inform listeners
                WindowDockChanged(dock);
            }

            // Save last dock position
            mLastDock = dock;
        }
Пример #22
0
        /// <summary>
        /// Monitors for size changes and detects if the window has been docked (Aero snap) to an edge
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            // Make sure our monitor info is up-to-date
            WmGetMinMaxInfo(IntPtr.Zero, IntPtr.Zero);

            // Get window rectangle
            var top    = mWindow.Top;
            var left   = mWindow.Left;
            var bottom = top + mWindow.Height;
            var right  = left + mWindow.Width;

            // Get window position/size in device pixels
            var windowTopLeft     = new Point(left, top);
            var windowBottomRight = new Point(right, bottom);

            // Check for edges docked
            var edgedTop    = windowTopLeft.Y <= (mScreenSize.Top + mEdgeTolerance) && windowTopLeft.Y >= (mScreenSize.Top - mEdgeTolerance);
            var edgedLeft   = windowTopLeft.X <= (mScreenSize.Left + mEdgeTolerance) && windowTopLeft.X >= (mScreenSize.Left - mEdgeTolerance);
            var edgedBottom = windowBottomRight.Y >= (mScreenSize.Bottom - mEdgeTolerance) && windowBottomRight.Y <= (mScreenSize.Bottom + mEdgeTolerance);
            var edgedRight  = windowBottomRight.X >= (mScreenSize.Right - mEdgeTolerance) && windowBottomRight.X <= (mScreenSize.Right + mEdgeTolerance);

            // Get docked position
            var dock = WindowDockPosition.Undocked;

            // Left docking
            if (edgedTop && edgedBottom && edgedLeft)
            {
                dock = WindowDockPosition.Left;
            }
            // Right docking
            else if (edgedTop && edgedBottom && edgedRight)
            {
                dock = WindowDockPosition.Right;
            }
            // Top/bottom
            else if (edgedTop && edgedBottom)
            {
                dock = WindowDockPosition.TopBottom;
            }
            // Top-left
            else if (edgedTop && edgedLeft)
            {
                dock = WindowDockPosition.TopLeft;
            }
            // Top-right
            else if (edgedTop && edgedRight)
            {
                dock = WindowDockPosition.TopRight;
            }
            // Bottom-left
            else if (edgedBottom && edgedLeft)
            {
                dock = WindowDockPosition.BottomLeft;
            }
            // Bottom-right
            else if (edgedBottom && edgedRight)
            {
                dock = WindowDockPosition.BottomRight;
            }

            // None
            else
            {
                dock = WindowDockPosition.Undocked;
            }

            // If dock has changed
            if (dock != mLastDock)
            {
                // Inform listeners
                WindowDockChanged(dock);
            }

            // Save last dock position
            mLastDock = dock;
        }
Пример #23
0
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            WmGetMinMaxInfo(IntPtr.Zero, IntPtr.Zero);
            _monitorDpi = VisualTreeHelper.GetDpi(_window);
            if (_monitorDpi == null)
            {
                return;
            }

            var top    = _window.Top;
            var left   = _window.Left;
            var bottom = top + _window.Height;
            var right  = left + _window.Width;

            var windowTopLeft     = new System.Windows.Point(left * _monitorDpi.Value.DpiScaleX, top * _monitorDpi.Value.DpiScaleX);
            var windowBottomRight = new System.Windows.Point(right * _monitorDpi.Value.DpiScaleX, bottom * _monitorDpi.Value.DpiScaleX);

            var edgedTop    = windowTopLeft.Y <= (_screenSize.Top + _edgeTolerance) && windowTopLeft.Y >= (_screenSize.Top - _edgeTolerance);
            var edgedLeft   = windowTopLeft.X <= (_screenSize.Left + _edgeTolerance) && windowTopLeft.X >= (_screenSize.Left - _edgeTolerance);
            var edgedBottom = windowBottomRight.Y >= (_screenSize.Bottom - _edgeTolerance) && windowBottomRight.Y <= (_screenSize.Bottom + _edgeTolerance);
            var edgedRight  = windowBottomRight.X >= (_screenSize.Right - _edgeTolerance) && windowBottomRight.X <= (_screenSize.Right + _edgeTolerance);

            var dock = WindowDockPosition.Undocked;

            if (edgedTop && edgedBottom && edgedLeft)
            {
                dock = WindowDockPosition.Left;
            }
            else if (edgedTop && edgedBottom && edgedRight)
            {
                dock = WindowDockPosition.Right;
            }
            else if (edgedTop && edgedBottom)
            {
                dock = WindowDockPosition.TopBottom;
            }
            else if (edgedTop && edgedLeft)
            {
                dock = WindowDockPosition.TopLeft;
            }
            else if (edgedTop && edgedRight)
            {
                dock = WindowDockPosition.TopRight;
            }
            else if (edgedBottom && edgedLeft)
            {
                dock = WindowDockPosition.BottomLeft;
            }
            else if (edgedBottom && edgedRight)
            {
                dock = WindowDockPosition.BottomRight;
            }
            else
            {
                dock = WindowDockPosition.Undocked;
            }

            if (dock != _lastDock)
            {
                WindowDockChanged(dock);
            }

            _lastDock = dock;
        }
Пример #24
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public WindowViewModel(Window window)
        {
            mWindow = window;

            // Listen out for the window resizing
            mWindow.StateChanged += (sender, e) =>
            {
                // Fire off events for all properties that are affected by a resize
                WindowResized();
            };

            // Create commands
            MinimizeCommand = new RelayCommand(() => mWindow.WindowState = WindowState.Minimized);
            MaximizeCommand = new RelayCommand(() => mWindow.WindowState ^= WindowState.Maximized);
            CloseCommand    = new RelayCommand(() => mWindow.Close());
            V = new RelayCommand(() => { if (CurrentBuilding != null)
                                         {
                                             changeViewEnterB(CurrentBuilding);
                                         }
                                 });
            F = new RelayCommand(() => { if (CurrentBuilding != null)
                                         {
                                             changeViewFractions(CurrentBuilding);
                                         }
                                 });
            B = new RelayCommand(() => { if (CurrentBuilding != null)
                                         {
                                             changeViewFinancesPage(CurrentBuilding);
                                         }
                                 });
            C = new RelayCommand(() => { if (CurrentBuilding != null)
                                         {
                                             changeViewCondominosPage();
                                         }
                                 });
            Q = new RelayCommand(() => { if (CurrentBuilding != null)
                                         {
                                             changeviewQuotaPage(CurrentBuilding);
                                         }
                                 });
            A = new RelayCommand(() => { if (CurrentBuilding != null)
                                         {
                                             changeViewAgendaPage(CurrentBuilding);
                                         }
                                 });
            R = new RelayCommand(() => { if (CurrentBuilding != null)
                                         {
                                             changeViewReunionPage(CurrentBuilding);
                                         }
                                 });
            O = new RelayCommand(() => { if (CurrentBuilding != null)
                                         {
                                             changeViewOrcamentoPage(CurrentBuilding);
                                         }
                                 });
            M = new RelayCommand(() => { if (CurrentBuilding != null)
                                         {
                                             changeViewManutencaoPage(CurrentBuilding);
                                         }
                                 });


            Buildings = new ObservableCollection <Predio>(Predio.get_All_Buildings());

            // Fix window resize issue
            mWindowResizer = new WindowResizer(mWindow);

            // Listen out for dock changes
            mWindowResizer.WindowDockChanged += (dock) =>
            {
                // Store last position
                mDockPosition = dock;

                // Fire off resize events
                WindowResized();
            };


            pages = new List <UserControl>(new UserControl[Enum.GetNames(typeof(ApplicationPage)).Length]);

            changeViewInitialPage();
        }
Пример #25
0
	/// <summary>
	/// The dock position of the window
	/// </summary>
	public enum WindowDockPosition
		{
				/// <summary>
				/// Not docked
				/// </summary>
				Undocked,
				/// <summary>
				/// Docked to the left of the screen
				/// </summary>
				Left,
				/// <summary>
				/// Docked to the right of the screen
				/// </summary>
				Right,
		}

		/// <summary>
		/// Fixes the issue with Windows of Style <see cref="WindowStyle.None"/> covering the taskbar
		/// </summary>
		public class WindowResizer
		{
				#region Private Members

				/// <summary>
				/// The window to handle the resizing for
				/// </summary>
				private Window mWindow;

				/// <summary>
				/// The last calculated available screen size
				/// </summary>
				private Rect mScreenSize = new Rect();

				/// <summary>
				/// How close to the edge the window has to be to be detected as at the edge of the screen
				/// </summary>
				private int mEdgeTolerance = 2;

				/// <summary>
				/// The transform matrix used to convert WPF sizes to screen pixels
				/// </summary>
				private Matrix mTransformToDevice;

				/// <summary>
				/// The last screen the window was on
				/// </summary>
				private IntPtr mLastScreen;

				/// <summary>
				/// The last known dock position
				/// </summary>
				private WindowDockPosition mLastDock = WindowDockPosition.Undocked;

				#endregion

				#region Dll Imports

				[DllImport("user32.dll")]
				[return: MarshalAs(UnmanagedType.Bool)]
				static extern bool GetCursorPos(out POINT lpPoint);

				[DllImport("user32.dll")]
				static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);

				[DllImport("user32.dll", SetLastError = true)]
				static extern IntPtr MonitorFromPoint(POINT pt, MonitorOptions dwFlags);

				#endregion

				#region Public Events

				/// <summary>
				/// Called when the window dock position changes
				/// </summary>
				public event Action<WindowDockPosition> WindowDockChanged = (dock) => { };

				#endregion

				#region Public Properties

				/// <summary>
				/// The size and position of the current monitor the window is on
				/// </summary>
				public Rectangle CurrentMonitorSize { get; set; } = new Rectangle();

				#endregion

				#region Constructor

				/// <summary>
				/// Default constructor
				/// </summary>
				/// <param name="window">The window to monitor and correctly maximize</param>
				/// <param name="adjustSize">The callback for the host to adjust the maximum available size if needed</param>
				public WindowResizer(Window window)
				{
						mWindow = window;

						// Create transform visual (for converting WPF size to pixel size)
						GetTransform();

						// Listen out for source initialized to setup
						mWindow.SourceInitialized += Window_SourceInitialized;

						// Monitor for edge docking
						mWindow.SizeChanged += Window_SizeChanged;
				}

				#endregion

				#region Initialize

				/// <summary>
				/// Gets the transform object used to convert WPF sizes to screen pixels
				/// </summary>
				private void GetTransform()
				{
						// Get the visual source
						var source = PresentationSource.FromVisual(mWindow);

						// Reset the transform to default
						mTransformToDevice = default(Matrix);

						// If we cannot get the source, ignore
						if (source == null)
								return;

						// Otherwise, get the new transform object
						mTransformToDevice = source.CompositionTarget.TransformToDevice;
				}

				/// <summary>
				/// Initialize and hook into the windows message pump
				/// </summary>
				/// <param name="sender"></param>
				/// <param name="e"></param>
				private void Window_SourceInitialized(object sender, System.EventArgs e)
				{
						// Get the handle of this window
						var handle = (new WindowInteropHelper(mWindow)).Handle;
						var handleSource = HwndSource.FromHwnd(handle);

						// If not found, end
						if (handleSource == null)
								return;

						// Hook into it's Windows messages
						handleSource.AddHook(WindowProc);
				}

				#endregion

				#region Edge Docking

				/// <summary>
				/// Monitors for size changes and detects if the window has been docked (Aero snap) to an edge
				/// </summary>
				/// <param name="sender"></param>
				/// <param name="e"></param>
				private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
				{
						// We cannot find positioning until the window transform has been established
						if (mTransformToDevice == default(Matrix))
								return;

						// Get the WPF size
						var size = e.NewSize;

						// Get window rectangle
						var top = mWindow.Top;
						var left = mWindow.Left;
						var bottom = top + size.Height;
						var right = left + mWindow.Width;

						// Get window position/size in device pixels
						var windowTopLeft = mTransformToDevice.Transform(new Point(left, top));
						var windowBottomRight = mTransformToDevice.Transform(new Point(right, bottom));

						// Check for edges docked
						var edgedTop = windowTopLeft.Y <= (mScreenSize.Top + mEdgeTolerance);
						var edgedLeft = windowTopLeft.X <= (mScreenSize.Left + mEdgeTolerance);
						var edgedBottom = windowBottomRight.Y >= (mScreenSize.Bottom - mEdgeTolerance);
						var edgedRight = windowBottomRight.X >= (mScreenSize.Right - mEdgeTolerance);

						// Get docked position
						var dock = WindowDockPosition.Undocked;

						// Left docking
						if (edgedTop && edgedBottom && edgedLeft)
								dock = WindowDockPosition.Left;
						else if (edgedTop && edgedBottom && edgedRight)
								dock = WindowDockPosition.Right;
						// None
						else
								dock = WindowDockPosition.Undocked;

						// If dock has changed
						if (dock != mLastDock)
								// Inform listeners
								WindowDockChanged(dock);

						// Save last dock position
						mLastDock = dock;
				}

				#endregion

				#region Windows Proc

				/// <summary>
				/// Listens out for all windows messages for this window
				/// </summary>
				/// <param name="hwnd"></param>
				/// <param name="msg"></param>
				/// <param name="wParam"></param>
				/// <param name="lParam"></param>
				/// <param name="handled"></param>
				/// <returns></returns>
				private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
				{
						switch (msg)
						{
								// Handle the GetMinMaxInfo of the Window
								case 0x0024:/* WM_GETMINMAXINFO */
										WmGetMinMaxInfo(hwnd, lParam);
										handled = true;
										break;
						}

						return (IntPtr)0;
				}

				#endregion

				/// <summary>
				/// Get the min/max window size for this window
				/// Correctly accounting for the taskbar size and position
				/// </summary>
				/// <param name="hwnd"></param>
				/// <param name="lParam"></param>
				private void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
				{
						// Get the point position to determine what screen we are on
						GetCursorPos(out POINT lMousePosition);
						
						// Get the primary monitor at cursor position 0,0
						var lPrimaryScreen = MonitorFromPoint(new POINT(0, 0), MonitorOptions.MONITOR_DEFAULTTOPRIMARY);

						// Try and get the primary screen information
						var lPrimaryScreenInfo = new MONITORINFO();
						if (GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false)
								return;

						// Now get the current screen
						var lCurrentScreen = MonitorFromPoint(lMousePosition, MonitorOptions.MONITOR_DEFAULTTONEAREST);

						// If this has changed from the last one, update the transform
						if (lCurrentScreen != mLastScreen || mTransformToDevice == default(Matrix))
								GetTransform();

						// Store last know screen
						mLastScreen = lCurrentScreen;

						// Get min/max structure to fill with information
						var lMmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));

						// If it is the primary screen, use the rcWork variable
						if (lPrimaryScreen.Equals(lCurrentScreen) == true)
						{
								lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcWork.Left;
								lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcWork.Top;
								lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcWork.Right - lPrimaryScreenInfo.rcWork.Left;
								lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcWork.Bottom - lPrimaryScreenInfo.rcWork.Top;
						}
						// Otherwise it's the rcMonitor values
						else
						{
								lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcMonitor.Left;
								lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcMonitor.Top;
								lMmi.ptMaxSize.X = lPrimaryScreenInfo.rcMonitor.Right - lPrimaryScreenInfo.rcMonitor.Left;
								lMmi.ptMaxSize.Y = lPrimaryScreenInfo.rcMonitor.Bottom - lPrimaryScreenInfo.rcMonitor.Top;
						}

						// Set monitor size
						CurrentMonitorSize = new Rectangle(lMmi.ptMaxPosition.X, lMmi.ptMaxPosition.Y, lMmi.ptMaxSize.X + lMmi.ptMaxPosition.X, lMmi.ptMaxSize.Y + lMmi.ptMaxPosition.Y);

						// Set min size
						var minSize = mTransformToDevice.Transform(new Point(mWindow.MinWidth, mWindow.MinHeight));

						lMmi.ptMinTrackSize.X = (int)minSize.X;
						lMmi.ptMinTrackSize.Y = (int)minSize.Y;

						// Store new size
						mScreenSize = new Rect(lMmi.ptMaxPosition.X, lMmi.ptMaxPosition.Y, lMmi.ptMaxSize.X, lMmi.ptMaxSize.Y);

						// Now we have the max size, allow the host to tweak as needed
						Marshal.StructureToPtr(lMmi, lParam, true);
				}
		}

		#region Dll Helper Structures

		enum MonitorOptions : uint
		{
				MONITOR_DEFAULTTONULL = 0x00000000,
				MONITOR_DEFAULTTOPRIMARY = 0x00000001,
				MONITOR_DEFAULTTONEAREST = 0x00000002
		}


		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
		public class MONITORINFO
		{
				public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
				public Rectangle rcMonitor = new Rectangle();
				public Rectangle rcWork = new Rectangle();
				public int dwFlags = 0;
		}


		[StructLayout(LayoutKind.Sequential)]
		public struct Rectangle
		{
				public int Left, Top, Right, Bottom;

				public Rectangle(int left, int top, int right, int bottom)
				{
						this.Left = left;
						this.Top = top;
						this.Right = right;
						this.Bottom = bottom;
				}
		}

		[StructLayout(LayoutKind.Sequential)]
		public struct MINMAXINFO
		{
				public POINT ptReserved;
				public POINT ptMaxSize;
				public POINT ptMaxPosition;
				public POINT ptMinTrackSize;
				public POINT ptMaxTrackSize;
		};

		[StructLayout(LayoutKind.Sequential)]
		public struct POINT
		{
				/// <summary>
				/// x coordinate of point.
				/// </summary>
				public int X;
				/// <summary>
				/// y coordinate of point.
				/// </summary>
				public int Y;

				/// <summary>
				/// Construct a point of coordinates (x,y).
				/// </summary>
				public POINT(int x, int y)
				{
						this.X = x;
						this.Y = y;
				}
		}

		#endregion
}
Пример #26
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public WindowViewModel(Window window)
        {
            mWindow = window;

            // Listen out for the window resizing
            mWindow.StateChanged += (sender, e) =>
            {
                // Fire off events for all properties that are affected by a resize
                WindowResized();
            };

            // Create commands
            //MenuCommand = new RelayCommand(x => SystemCommands.ShowSystemMenu(mWindow, GetMousePosition()));

            // Fix window resize issue
            var resizer = new WindowResizer(mWindow);

            // Listen out for dock changes
            resizer.WindowDockChanged += (dock) =>
            {
                // Store last position
                mDockPosition = dock;
                // Fire off resize events
                WindowResized();
            };

            string infoURL = "http://212.182.24.47:3001/news";

            InfoPageViewModel.RootObject infoObject;
            using (var webClient = new System.Net.WebClient())
            {
                var json = webClient.DownloadString(infoURL);
                infoObject = JsonConvert.DeserializeObject <InfoPageViewModel.RootObject>(json);
                foreach (InfoPageViewModel.Payload payload in infoObject.payload)
                {
                    BitmapSource bitmapSource = new BitmapImage(new Uri(payload.url));
                    payload.source = bitmapSource;
                }
            }

            string instaURL = "http://212.182.24.47:3001/instagram";

            InstaPageViewModel.RootObject instaObject;
            using (var webClient = new System.Net.WebClient())
            {
                var json = webClient.DownloadString(instaURL);
                instaObject = JsonConvert.DeserializeObject <InstaPageViewModel.RootObject>(json);
                foreach (InstaPageViewModel.Payload payload in instaObject.payload)
                {
                    // to do
                    BitmapSource bitmapSource = new BitmapImage(new Uri(payload.photo_url));
                    //bitmapSource.Freeze();
                    payload.source = bitmapSource;
                }
            }

            PageViewModels.Add(new InfoPageViewModel(infoObject));
            PageViewModels.Add(new InstaPageViewModel(instaObject));
            PageViewModels.Add(new BusesPageViewModel());
            PageViewModels.Add(new DabPageViewModel());

            CurrentPageViewModel = PageViewModels[3];

            Mediator.Subscribe("GoTo1Screen", OnGo1Screen);
            Mediator.Subscribe("GoTo2Screen", OnGo2Screen);
            Mediator.Subscribe("GoTo3Screen", OnGo3Screen);
            Mediator.Subscribe("GoTo4Screen", OnGo4Screen);
        }