Esempio n. 1
0
        public TextBoxControl(bool hideTag, TextBoxType textBoxType, AWPropertyAttribute attribute)
        {
            InitializeComponent();

            if (hideTag)
            {
                TagLabel.Visibility = Visibility.Collapsed;
            }

            if (attribute is AWFilePathAttribute filePathAttribute)
            {
                Element.Visibility     = Visibility.Collapsed;
                PathElement.Visibility = Visibility.Visible;

                VisualHelper.LeftClick(PathElement, _ =>
                {
                    if (DataContext is VisualTypeContext context)
                    {
                        context.Value = VisualHelper.SelectFile(filePathAttribute.Message, filePathAttribute.Filter, context.Value?.ToString(), filePathAttribute.OnlyFolder);
                    }
                });
            }
            else
            {
                if (attribute is AWLimitAttribute limitAttribute && limitAttribute.MaxLength > 0)
                {
                    Element.MaxLength = limitAttribute.MaxLength;
                }

                if (textBoxType != TextBoxType.String)
                {
                    VisualHelper.LimitInput(Element, textBoxType == TextBoxType.Double ? LimitType.Double : LimitType.Int, (attribute as AWLimitAttribute)?.AllowedStrings);
                }

                VisualHelper.ExitOnEnter(Element);
            }
        }
Esempio n. 2
0
        protected override void OnDataContextChange()
        {
            if (DataContext is IMenuItem item)
            {
                if (item.CanChangeGroup)
                {
                    VisualHelper.LeftDown(Element, _ =>
                    {
                        DragDrop.DoDragDrop(Element, item, DragDropEffects.Move);
                    });
                }

                Element.ContentMargin = new Thickness(item.Left, 0, 0, 0);

                if (item.Actions == null)
                {
                    item.Actions = new List <IContextMenuAction>();
                }

                if (item is IMenuGroup group)
                {
                    Container.AllowDrop = true;

                    Container.Drop -= OnDrop;
                    Container.Drop += OnDrop;

                    Group.Visibility = Visibility.Visible;

                    foreach (IContextMenuAction menuAction in item.Actions.Where(a => a.Header == group.CreateItemHint).ToList())
                    {
                        item.Actions.Remove(menuAction);
                    }

                    if (group.ViewCreateItem)
                    {
                        item.Actions.Add(new ContextMenuActionContext(group.CreateItemHint, PackIconKind.Add, () =>
                        {
                            IsCreate      = true;
                            IsCreateGroup = false;

                            Edit.Text = "";
                            HintAssist.SetHint(Edit, group.CreateItemHint);

                            Element.HideHeader = true;
                            Edit.Visibility    = Visibility.Visible;

                            Dispatcher.BeginInvoke(DispatcherPriority.Input,
                                                   new Action(() =>
                            {
                                Edit.Focus();
                                Keyboard.Focus(Edit);
                                Edit.CaretIndex = 0;
                            }));
                        }));
                    }

                    foreach (IContextMenuAction menuAction in item.Actions.Where(a => a.Header == group.CreateGroupHint).ToList())
                    {
                        item.Actions.Remove(menuAction);
                    }

                    if (group.ViewCreateGroup)
                    {
                        item.Actions.Add(new ContextMenuActionContext(group.CreateGroupHint, PackIconKind.FolderAdd, () =>
                        {
                            IsCreate      = false;
                            IsCreateGroup = true;

                            Edit.Text = "";
                            HintAssist.SetHint(Edit, group.CreateGroupHint);

                            Element.HideHeader = true;
                            Edit.Visibility    = Visibility.Visible;

                            Dispatcher.BeginInvoke(DispatcherPriority.Input,
                                                   new Action(() =>
                            {
                                Edit.Focus();
                                Keyboard.Focus(Edit);
                                Edit.CaretIndex = 0;
                            }));
                        }));
                    }
                }

                foreach (IContextMenuAction menuAction in item.Actions.Where(a => a.Header == AWWindow.RenameTitle).ToList())
                {
                    item.Actions.Remove(menuAction);
                }

                if (item.ViewRename)
                {
                    item.Actions.Add(new ContextMenuActionContext(AWWindow.RenameTitle, PackIconKind.RenameBox, () =>
                    {
                        IsCreate      = false;
                        IsCreateGroup = false;

                        Edit.Text = item.Header;
                        HintAssist.SetHint(Edit, AWWindow.NewNameTitle);

                        Element.HideHeader = true;
                        Edit.Visibility    = Visibility.Visible;

                        Dispatcher.BeginInvoke(DispatcherPriority.Input,
                                               new Action(() =>
                        {
                            Edit.Focus();
                            Keyboard.Focus(Edit);
                            Edit.CaretIndex = item.Header.Length;
                        }));
                    }));
                }

                foreach (IContextMenuAction menuAction in item.Actions.Where(a => a.Header == AWWindow.RemoveTitle).ToList())
                {
                    item.Actions.Remove(menuAction);
                }

                if (item.ViewRemove)
                {
                    item.Actions.Add(new ContextMenuActionContext(AWWindow.RemoveTitle, PackIconKind.Close, () =>
                    {
                        if (item.OnRemove?.Invoke(item) == true)
                        {
                            item.Group?.RemoveItem(item);
                        }
                    })
                    {
                        SeparatorStyle = SeparatorStyle.Top,
                        IconColor      = ColorHelper.RedSet.Color500.ToBrush()
                    });
                }

                foreach (IContextMenuAction menuAction in item.Actions)
                {
                    (menuAction.Command as SimpleCommand).OnExecute = () => Menu.IsOpen = false;
                }

                (item as BaseContext).Notify(nameof(item.Actions));

                VisualHelper.ExitOnEnter(Edit, () =>
                {
                    OnEdit(item);
                });
            }
        }