Пример #1
0
        private ContextMenu CreateItemContextMenu(Project1UIDesignItem item)
        {
            var menu         = new ContextMenu();
            var itemRemove   = new MenuItem();
            var controlPoint = item.RenderTransform as TranslateTransform;

            itemRemove.Header = "删除此元素";
            itemRemove.Click += (s, e) =>
            {
                Children.Remove(item);
            };
            var itemHcenter = new MenuItem();

            itemHcenter.Header = "水平居中";
            itemHcenter.Click += (s, e) =>
            {
                controlPoint.X = this.ActualWidth / 2 - item.ActualWidth / 2;
            };
            var itemVcenter = new MenuItem();

            itemVcenter.Header = "垂直居中";
            itemVcenter.Click += (s, e) =>
            {
                controlPoint.Y = this.ActualHeight / 2 - item.ActualHeight / 2;
            };
            menu.Items.Add(itemRemove);
            menu.Items.Add(itemHcenter);
            menu.Items.Add(itemVcenter);


            return(menu);
        }
Пример #2
0
        private void HandleItem(Project1UIDesignItem item)
        {
            item.ControlPointMouseDown += Control_ControlPointMouseDown;
            item.ControlPointMouseUp   += Control_ControlPointMouseUp;

            item.MouseLeftButtonUp   += Control_MouseLeftButtonUp;
            item.MouseMove           += Control_MouseMove;
            item.MouseLeave          += Control_MouseLeave;
            item.MouseLeftButtonDown += Control_MouseLeftButtonDown;
            item.MouseRightButtonUp  += Control_MouseRightButtonUp;
            item.ContextMenu          = CreateItemContextMenu(item);
        }
        private ContextMenu CreateItemContextMenu(Project1UIDesignItem item)
        {
            var menu         = new ContextMenu();
            var itemRemove   = new MenuItem();
            var controlPoint = item.RenderTransform as TranslateTransform;

            itemRemove.Header = $"{Application.Current.Resources["Lang_Delete"]}";
            itemRemove.Click += (s, e) =>
            {
                Children.Remove(item);
            };
            var itemHcenter = new MenuItem();

            itemHcenter.Header = $"{Application.Current.Resources["Lang_HorizontalCenter"]}";
            itemHcenter.Click += (s, e) =>
            {
                controlPoint.X = this.ActualWidth / 2 - item.ActualWidth / 2;
            };
            var itemVcenter = new MenuItem();

            itemVcenter.Header = $"{Application.Current.Resources["Lang_VerticalCenter"]}";
            itemVcenter.Click += (s, e) =>
            {
                controlPoint.Y = this.ActualHeight / 2 - item.ActualHeight / 2;
            };
            var itemAtt = new MenuItem();

            itemAtt.Header = $"{Application.Current.Resources["Lang_Attribute"]}";
            itemAtt.Click += (s, e) =>
            {
                item.OpenAttPopup();
            };
            menu.Items.Add(itemRemove);
            menu.Items.Add(itemHcenter);
            menu.Items.Add(itemVcenter);
            menu.Items.Add(itemAtt);


            return(menu);
        }
Пример #4
0
        public void ImportElements(List <ElementModel> elements)
        {
            if (elements != null)
            {
                foreach (var element in elements)
                {
                    var item         = new Project1UIDesignItem();
                    var itemModel    = item.DataContext as DesignItemModel;
                    var controlPoint = item.RenderTransform as TranslateTransform;
                    //分配共用的属性
                    itemModel.Width   = element.Width;
                    itemModel.Height  = element.Height;
                    itemModel.Opacity = element.Opacity;
                    controlPoint.X    = element.X;
                    controlPoint.Y    = element.Y;
                    //分配独有的属性
                    switch (element.Type)
                    {
                    case DesignItemType.Button:
                        var button = new Project1UIButton();
                        if (element.Style != null)
                        {
                            var res = this.TryFindResource(element.Style);
                            if (res != null)
                            {
                                button.Style = res as Style;
                            }
                            else
                            {
                                res = this.TryFindResource("default");
                                if (res != null)
                                {
                                    button.Style = res as Style;
                                }
                            }
                        }
                        itemModel.ButtonText      = element.Text;
                        itemModel.ButtonStyleName = element.Style;
                        itemModel.IsFontBold      = element.IsTextBold;
                        itemModel.FontSize        = element.FontSize;
                        itemModel.Command         = element.Command;
                        item.Content = button;
                        break;

                    case DesignItemType.Image:
                        var image = new Image();
                        itemModel.Image = element.Image;
                        item.Content    = image;
                        break;

                    case DesignItemType.Text:
                        var text = new TextBlock();
                        itemModel.Text       = element.Text;
                        itemModel.TextColor  = element.TextColor;
                        itemModel.IsFontBold = element.IsTextBold;
                        itemModel.FontSize   = element.FontSize;
                        item.Content         = text;
                        break;
                    }
                    //将生成的元素加入设计容器界面
                    HandleItem(item);
                    this.Children.Add(item);
                }
            }
        }
Пример #5
0
        private ContextMenu CreateContextMenu()
        {
            var menu    = new ContextMenu();
            var itemAdd = new MenuItem();

            itemAdd.Header = "添加元素";
            //图片
            var itemAddImage = new MenuItem();

            itemAddImage.Header = "图片";
            itemAddImage.Click += (s, e) =>
            {
                var item = new Project1UIDesignItem();
                var data = item.DataContext as DesignItemModel;
                data.Image  = "pack://application:,,,/Project1.UI;component/Assets/Images/sunglasses.png";
                data.Width  = 100;
                data.Height = 100;
                var image = new Image();
                //image.Source = new BitmapImage(new Uri("pack://application:,,,/Project1.UI;component/Assets/Images/sunglasses.png", UriKind.RelativeOrAbsolute));
                item.Content = image;
                HandleItem(item);
                this.Children.Add(item);
            };
            //按钮
            var itemAddButton = new MenuItem();

            itemAddButton.Header = "按钮";
            itemAddButton.Click += (s, e) =>
            {
                var item = new Project1UIDesignItem();
                var data = item.DataContext as DesignItemModel;
                data.ButtonText = "按钮";
                data.Width      = 100;
                data.Height     = 25;
                var element = new Project1UIButton();

                item.Content = element;
                HandleItem(item);
                this.Children.Add(item);
            };
            //文本
            var itemAddText = new MenuItem();

            itemAddText.Header = "文本";
            itemAddText.Click += (s, e) =>
            {
                var item = new Project1UIDesignItem();
                var data = item.DataContext as DesignItemModel;
                data.Text   = "文本";
                data.Width  = 100;
                data.Height = 25;
                var element = new TextBlock();
                element.TextWrapping = TextWrapping.Wrap;
                item.Content         = element;
                HandleItem(item);
                this.Children.Add(item);
            };
            //属性编辑
            var itemAttr = new MenuItem();

            itemAttr.Header = "属性";
            itemAttr.Click += (s, e) =>
            {
                isContextMenuOpen = true;
                attrPopup.IsOpen  = true;
            };
            itemAdd.Items.Add(itemAddText);
            itemAdd.Items.Add(itemAddImage);
            itemAdd.Items.Add(itemAddButton);

            menu.Items.Add(itemAdd);
            menu.Items.Add(itemAttr);


            return(menu);
        }