Example #1
0
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            base.OnTemplateApplied(e);

            ContextMenu = new ContextMenu
            {
                DataContext = this,
                Items       = new Avalonia.Controls.Controls()
            };

            if (IsCopyEnabled)
            {
                var copyPresenter = new DrawingPresenter
                {
                    Drawing = new GeometryDrawing
                    {
                        Brush    = Brushes.LightGray,
                        Geometry = Geometry.Parse(
                            "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z")
                    },
                    Width  = 16,
                    Height = 16
                };
                (ContextMenu.Items as Avalonia.Controls.Controls).Add(new MenuItem {
                    Header = "Copy", Command = CopyCommand, Icon = copyPresenter
                });
            }

            if (!IsReadOnly)
            {
                CreatePasteItem();
                (ContextMenu.Items as Avalonia.Controls.Controls).Add(_pasteItem);
            }
        }
Example #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainForm         form      = new MainForm();
            DrawingPresenter presenter = new DrawingPresenter(form);

            Application.Run(form);
        }
Example #3
0
        private Control CreateMarker()
        {
            var marker = new DrawingPresenter();

            marker.PointerPressed += (o, e) => { e.Handled = true; MarkerPointerDown?.Invoke(o, e); };
            marker[~DrawingPresenter.DrawingProperty] = this[~MarkerImageProperty];
            marker[~ToolTip.TipProperty] = this[~MessageProperty];
            VisualChildren.Add(marker);
            LogicalChildren.Add(marker);
            return(marker);
        }
            public object Create()
            {
                var image = new DrawingPresenter
                {
                    Width   = 16,
                    Height  = 16,
                    Drawing = Glyph.ToImageSource()
                };

                return(image);
            }
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            btnDownload = this.Find <Button>("btnDownload");
            btnCopyLink = this.Find <Button>("btnCopyLink");
            iconCheck   = this.Find <DrawingPresenter>("iconCheck");

            btnCopyLink.Subscribe(Button.ClickEvent, BtnCopyLink_Click);
            btnDownload.Subscribe(Button.ClickEvent, BtnDownload_Click);
        }
Example #6
0
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            _drawingPresenter = this.FindControl <DrawingPresenter>("drawingPresenter");

            DispatcherTimer.Run(() =>
            {
                UpdateGlyphRun();

                return(true);
            }, TimeSpan.FromSeconds(1));
        }
Example #7
0
        private Control CreateMarker()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var marker = new DrawingPresenter();
#pragma warning restore CS0618 // Type or member is obsolete
            marker.PointerPressed += (o, e) => { e.Handled = true; MarkerPointerDown?.Invoke(o, e); };
#pragma warning disable CS0618 // Type or member is obsolete
            marker[~DrawingPresenter.DrawingProperty] = this[~MarkerImageProperty];
#pragma warning restore CS0618 // Type or member is obsolete
            marker[~ToolTip.TipProperty] = this[~MessageProperty];
            VisualChildren.Add(marker);
            LogicalChildren.Add(marker);
            return(marker);
        }
Example #8
0
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            base.OnTemplateApplied(e);

            ContextMenu = new ContextMenu
            {
                DataContext = this,
            };
            var pastePresenter = new DrawingPresenter
            {
                Drawing = new GeometryDrawing
                {
                    Brush    = Brushes.LightGray,
                    Geometry = Geometry.Parse(
                        @"M19,20H5V4H7V7H17V4H19M12,2A1,1 0 0,1 13,3A1,1 0 0,1 12,4A1,1 0 0,1 11,3A1,1 0 0,1 12,2M19,2H14.82C14.4,0.84 
                    13.3,0 12,0C10.7,0 9.6,0.84 9.18,2H5A2,2 0 0,0 3,4V20A2,2 0 0,0 5,22H19A2,2 0 0,0 21,20V4A2,2 0 0,0 19,2Z")
                },
                Width  = 16,
                Height = 16,
            };
            var copyPresenter = new DrawingPresenter
            {
                Drawing = new GeometryDrawing
                {
                    Brush    = Brushes.LightGray,
                    Geometry = Geometry.Parse(
                        "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z")
                },
                Width  = 16,
                Height = 16
            };

            _pasteItem = new MenuItem {
                Header = "Paste", Command = PasteCommand, Icon = pastePresenter
            };

            ContextMenu.Items = new Avalonia.Controls.Controls
            {
                new MenuItem {
                    Header = "Copy", Command = CopyCommand, Icon = copyPresenter
                }
            };

            if (!IsReadOnly)
            {
                (ContextMenu.Items as Avalonia.Controls.Controls).Add(_pasteItem);
            }
        }
        public ContextActionsBulbPopup(Control parent) : base(parent)
        {
            UseLayoutRounding = true;

            StaysOpen = true;

            _headerImage = new DrawingPresenter();

            _mainItem = new MenuItem
            {
                Styles = { CreateItemContainerStyle() },
                Header = _headerImage
            };

            _mainItem.SubmenuOpened += (sender, args) =>
            {
                if (ReferenceEquals(sender, _mainItem))
                {
                    _isOpen = true;
                    MenuOpened?.Invoke(this, EventArgs.Empty);
                }
            };

            Closed += (sender, args) =>
            {
                if (_isOpen)
                {
                    _isOpen = false;
                    MenuClosed?.Invoke(this, EventArgs.Empty);
                }
            };

            var menu = new Menu
            {
                Background      = Brushes.Transparent,
                BorderBrush     = _mainItem.BorderBrush,
                BorderThickness = _mainItem.BorderThickness,
                Items           = new[] { _mainItem }
            };

            Child = menu;
        }
Example #10
0
        private void CreatePasteItem()
        {
            if (_pasteItem != null)
            {
                return;
            }
            var pastePresenter = new DrawingPresenter
            {
                Drawing = new GeometryDrawing
                {
                    Brush    = Brushes.LightGray,
                    Geometry = Geometry.Parse(
                        @"M19,20H5V4H7V7H17V4H19M12,2A1,1 0 0,1 13,3A1,1 0 0,1 12,4A1,1 0 0,1 11,3A1,1 0 0,1 12,2M19,2H14.82C14.4,0.84
							13.3,0 12,0C10.7,0 9.6,0.84 9.18,2H5A2,2 0 0,0 3,4V20A2,2 0 0,0 5,22H19A2,2 0 0,0 21,20V4A2,2 0 0,0 19,2Z"                            )
                },
                Width  = 16,
                Height = 16,
            };

            _pasteItem = new MenuItem {
                Header = "Paste", Command = PasteCommand, Icon = pastePresenter
            };
        }
Example #11
0
        public ContextActionsBulbPopup(Control parent, Control placementTarget)
        {
            ((ISetLogicalParent)this).SetParent(parent);

            _placementTarget = placementTarget;

            UseLayoutRounding = true;

            StaysOpen = true;

            if (Application.Current.Styles.TryGetResource("Bulb", out object bulbIcon))
            {
                _headerImage = new DrawingPresenter
                {
                    Drawing = bulbIcon as Drawing,
                    Height  = 16,
                    Width   = 16
                };
            }

            _mainItem = new MenuItem
            {
                Styles  = { CreateItemContainerStyle() },
                Header  = _headerImage,
                Margin  = new Thickness(),
                Padding = new Thickness()
            };

            _mainItem.SelectionChanged += (sender, args) =>
            {
                if (!_mainItem.IsSubMenuOpen)
                {
                    Close();
                }
            };

            _mainItem.SubmenuOpened += (sender, args) =>
            {
                if (ReferenceEquals(sender, _mainItem))
                {
                    _isOpen = true;
                    MenuOpened?.Invoke(this, EventArgs.Empty);
                }
            };

            Closed += (sender, args) =>
            {
                if (_isOpen)
                {
                    _isOpen = false;
                    MenuClosed?.Invoke(this, EventArgs.Empty);
                }
            };

            _mainMenu = new Menu
            {
                Background      = Brushes.Transparent,
                BorderBrush     = _mainItem.BorderBrush,
                BorderThickness = _mainItem.BorderThickness,
                Items           = new[] { _mainItem }
            };

            Child = _mainMenu;

            TextBlock.SetFontFamily(this, new FontFamily("Segoi UI"));
            TextBlock.SetFontSize(this, 14);
            TextBlock.SetForeground(this, Application.Current.Resources["ThemeForegroundBrush"] as IBrush);
        }