コード例 #1
0
 private void BtnClockwiseOnClick(object sender, RoutedEventArgs e)
 {
     _rotateDisplay.RunFor(NativeMethods.Dmdo270, _currentDisplayId);
     _rotateButtonAndCanvas.RunFor(NativeMethods.Dmdo270, _currentButton);
     SetWindowMargins();
 }
コード例 #2
0
        // ReSharper disable UseObjectOrCollectionInitializer
        private ContextMenu TaskbarIconContextMenu()
        {
            var contextMenu = new ContextMenu();

            foreach (var device in _activeDevices.Value.OrderBy(d => d.PositionX))
            {
                var currentButton = new Button();

                foreach (Canvas canvas in _mainWindow.DisplayStackPanel.Children)
                {
                    foreach (Button button in canvas.Children)
                    {
                        if (button.Name == $"ButtonDisplay{device.Id}")
                        {
                            currentButton = button;
                            break;
                        }
                    }
                }

                var parent = new MenuItem
                {
                    Header = device.Name
                };
                parent.Icon = new PackIconMaterial
                {
                    Kind = PackIconMaterialKind.Monitor
                };

                //anticlockwise
                var anticlockwiseItem = new MenuItem
                {
                    Header = "Upright 'anticlockwise'",
                    Icon   = new PackIconMaterial
                    {
                        Kind = PackIconMaterialKind.ChevronLeft
                    }
                };
                anticlockwiseItem.Click += (sender, args) =>
                {
                    _rotateDisplay.RunFor(NativeMethods.Dmdo90, device.Id);
                    _rotateButtonAndCanvas.RunFor(NativeMethods.Dmdo90, currentButton);
                    _mainWindow.SetWindowMargins();
                };

                //180
                var clockwiseItem = new MenuItem
                {
                    Header = "Landscape (rotated)",
                    Icon   = new PackIconMaterial
                    {
                        Kind = PackIconMaterialKind.ChevronUp
                    }
                };
                clockwiseItem.Click += (sender, args) =>
                {
                    _rotateDisplay.RunFor(NativeMethods.Dmdo180, device.Id);
                    _rotateButtonAndCanvas.RunFor(NativeMethods.Dmdo180, currentButton);
                    _mainWindow.SetWindowMargins();
                };

                //clockwise
                var mirrorItem = new MenuItem
                {
                    Header = "Upright 'clockwise'",
                    Icon   = new PackIconMaterial
                    {
                        Kind = PackIconMaterialKind.ChevronRight
                    }
                };
                mirrorItem.Click += (sender, args) =>
                {
                    _rotateDisplay.RunFor(NativeMethods.Dmdo270, device.Id);
                    _rotateButtonAndCanvas.RunFor(NativeMethods.Dmdo270, currentButton);
                    _mainWindow.SetWindowMargins();
                };

                //restore
                var restoreItem = new MenuItem
                {
                    Header = "Reset",
                    Icon   = new PackIconMaterial
                    {
                        Kind = PackIconMaterialKind.ChevronDown
                    }
                };
                restoreItem.Click += (sender, args) =>
                {
                    _rotateDisplay.RunFor(NativeMethods.DmdoDefault, device.Id);
                    _rotateButtonAndCanvas.RunFor(NativeMethods.DmdoDefault, currentButton);
                    _mainWindow.SetWindowMargins();
                };


                parent.Items.Add(anticlockwiseItem);
                parent.Items.Add(clockwiseItem);
                parent.Items.Add(mirrorItem);
                parent.Items.Add(restoreItem);
                contextMenu.Items.Add(parent);
            }

            var restoreApplication = new MenuItem
            {
                Header = "Restore application",
                Icon   = new PackIconMaterial
                {
                    Kind = PackIconMaterialKind.WindowRestore
                }
            };

            restoreApplication.Click += ContextMenuItemRestoreClick;

            var closeApplication = new MenuItem
            {
                Header = "Close application",
                Icon   = new PackIconMaterial
                {
                    Kind = PackIconMaterialKind.Power
                }
            };

            closeApplication.Click += ContextMenuItemCloseClick;

            contextMenu.Items.Add(new Separator());
            contextMenu.Items.Add(restoreApplication);
            contextMenu.Items.Add(closeApplication);


            return(contextMenu);
        }