Exemplo n.º 1
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (this.ContextMenuActions != null)
            {
                ContextMenu cm = new ContextMenu();
                for (int i = 0; i < this.ContextMenuActions.Count; ++i)
                {
                    MenuActionInfo info = this.ContextMenuActions[i];

                    MenuItem item = new MenuItem();
                    item.Header = info.Header;
                    if (!info.Icon.IsNullOrEmptyOrWhiteSpace())
                    {
                        item.Icon = StringImageConverter.Convert(info.Icon);
                    }
                    item.Click += (s, a) =>
                    {
                        info.DoOnClick(this, a);
                    };
                    cm.Items.Add(item);
                }
                this.ContextMenu = cm;
            }
        }
Exemplo n.º 2
0
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     if (value is string)
     {
         BitmapImage bi = StringImageConverter.Convert(value.ToSafeString());
         if (bi != null)
         {
             return(bi);
         }
         else if (this.IsWhenErrorReturnNull)
         {
             return(null);
         }
         else
         {
             return(Binding.DoNothing);
         }
     }
     else
     {
         if (this.IsWhenErrorReturnNull)
         {
             return(null);
         }
         else
         {
             return(Binding.DoNothing);
         }
     }
 }
Exemplo n.º 3
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this.PART_TextBox = this.Template.FindName("PART_TextBox", this) as XlyHighlightTextBox;

            if (this.ContextMenuActions == null)
            {
                return;
            }

            ContextMenu menu = new ContextMenu();

            for (int i = 0; i < this.ContextMenuActions.Count; ++i)
            {
                MenuActionInfo info = this.ContextMenuActions[i];
                MenuItem       item = new MenuItem();
                item.Header = info.Header;
                if (!info.Icon.IsNullOrEmptyOrWhiteSpace())
                {
                    Border border = new Border();
                    border.Background = new ImageBrush(StringImageConverter.Convert(info.Icon));
                    item.Icon         = border;
                }
                item.InputGestureText = info.KeyText;

                item.Click += (s, a) =>
                {
                    info.DoOnClick(this, a);
                };

                menu.Items.Add(item);
            }

            if (this.PART_TextBox.PART_RichTextBox == null)
            {
                this.PART_TextBox.ApplyTemplate();
            }

            this.PART_TextBox.PART_RichTextBox.ContextMenu = menu;
        }