예제 #1
0
 public IEnumerable <Control> GetControls(MetaAction metaAction)
 {
     return(controlAction.Where(it => Equals(it.Item1, metaAction)).Select(it =>
     {
         Control c;
         if (it.Item2.TryGetTarget(out c))
         {
             return c;
         }
         // if failed to get reference target
         return null;
     }).Where(it => it != null).ToArray());
 }
예제 #2
0
        public void Detach(MetaAction metaAction, Control control)
        {
            ValidateType(control);

            BindingOperations.ClearBinding(control, UIElement.IsEnabledProperty);
            BindingOperations.ClearBinding(control, UIElement.VisibilityProperty);

            Message.SetAttach(control, string.Empty);

            // Shortcut
            if (metaAction.KeyBinding != null)
            {
                var window = GetWindow(control);
                if (window.InputBindings.Contains(metaAction.KeyBinding))
                {
                    window.InputBindings.Remove(metaAction.KeyBinding);
                }
            }
        }
예제 #3
0
 public static void SetAction(DependencyObject element, MetaAction value)
 {
     element.SetValue(ActionProperty, value);
 }
예제 #4
0
 public static Image CreateImage(MetaAction source)
 {
     var result = new Image { Source = source.Icon.ToBitmapSource() };
     result.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
     return result;
 }
예제 #5
0
        public void Attach(MetaAction metaAction, Control control)
        {
            ValidateType(control);

            var existingItems = controlAction.Where(it => it.Item1 == metaAction);
            var targetItem    = existingItems.FirstOrDefault(it =>
            {
                Control c;
                if (it.Item2.TryGetTarget(out c))
                {
                    return(c.Equals(control));
                }
                return(false);
            });

            // already attached
            if (targetItem != null)
            {
                return;
            }
            Image image = null;

            if (metaAction.Icon != null)
            {
                image           = ImageHelper.CreateImage(metaAction);
                image.MaxWidth  = MetaAction.ToolBarIconSize;
                image.MaxHeight = MetaAction.ToolBarIconSize;
            }

            if (control is MenuItem)
            {
                var menu = (MenuItem)control;
                menu.Icon             = image;
                menu.InputGestureText = metaAction.ShortCut;
                menu.Header           = metaAction.Title;
                menu.ToolTip          = metaAction.ToolTip;
            }
            if (control is ButtonBase)
            {
                var button = (ButtonBase)control;
                button.Content = image;
                button.ToolTip = metaAction.ToolTip;
                if (!string.IsNullOrEmpty(metaAction.ShortCut))
                {
                    button.ToolTip += ": " + metaAction.ShortCut;
                }
            }

            control.SetValue(ToolTipService.ShowOnDisabledProperty, true);
            // IsEnabled property

            // Visibility
            control.SetBinding(UIElement.VisibilityProperty,
                               new Binding
            {
                Source              = metaAction,
                Path                = new PropertyPath("IsVisible"),
                Mode                = BindingMode.OneWay,
                Converter           = BooleanToVisibilityConverter.Instance,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
            });

            // Shortcut
            if (metaAction.KeyBinding != null)
            {
                var window = GetWindow(control);
                if (!window.InputBindings.Contains(metaAction.KeyBinding))
                {
                    window.InputBindings.Add(metaAction.KeyBinding);
                }
            }
            //  Message.SetAttach(control, metaAction.CaliburnAction);
            control.SetValue(Message.AttachProperty, metaAction.CaliburnAction);
            controlAction.Add(new Tuple <MetaAction, WeakReference <Control> >(metaAction, new WeakReference <Control>(control)));
        }
예제 #6
0
 /// <summary>
 /// Unregister action and remove it from all controls.
 /// </summary>
 /// <param name="action"></param>
 internal void UnregisterAction(MetaAction action)
 {
     actions.Remove(action);
 }
예제 #7
0
 internal void RegisterAction(MetaAction action)
 {
     actions.Add(action);
 }
        public void Attach(MetaAction metaAction, Control control)
        {
            ValidateType(control);

            var existingItems = controlAction.Where(it => it.Item1 == metaAction);
            var targetItem = existingItems.FirstOrDefault(it =>
            {
                Control c;
                if (it.Item2.TryGetTarget(out c))
                {
                    return c.Equals(control);
                }
                return false;
            });

            // already attached
            if (targetItem != null)
                return;
            Image image = null;
            if (metaAction.Icon != null)
            {
                image = ImageHelper.CreateImage(metaAction);
                image.MaxWidth = MetaAction.ToolBarIconSize;
                image.MaxHeight = MetaAction.ToolBarIconSize;
            }

            if (control is MenuItem)
            {
                var menu = (MenuItem)control;
                menu.Icon = image;
                menu.InputGestureText = metaAction.ShortCut;
                menu.Header = metaAction.Title;
                menu.ToolTip = metaAction.ToolTip;
            }
            if (control is ButtonBase)
            {
                var button = (ButtonBase)control;
                button.Content = image;
                button.ToolTip = metaAction.ToolTip;
                if (!string.IsNullOrEmpty(metaAction.ShortCut))
                {
                    button.ToolTip += ": " + metaAction.ShortCut;
                }
            }

            control.SetValue(ToolTipService.ShowOnDisabledProperty, true);
            // IsEnabled property

            // Visibility
            control.SetBinding(UIElement.VisibilityProperty,
                new Binding
                {
                    Source = metaAction,
                    Path = new PropertyPath("IsVisible"),
                    Mode = BindingMode.OneWay,
                    Converter = BooleanToVisibilityConverter.Instance,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                });

            // Shortcut
            if (metaAction.KeyBinding != null)
            {
                var window = GetWindow(control);
                if (!window.InputBindings.Contains(metaAction.KeyBinding))
                {
                    window.InputBindings.Add(metaAction.KeyBinding);
                }
            }
              //  Message.SetAttach(control, metaAction.CaliburnAction);
            control.SetValue(Message.AttachProperty, metaAction.CaliburnAction);
            controlAction.Add(new Tuple<MetaAction, WeakReference<Control>>(metaAction, new WeakReference<Control>(control)));
        }
 /// <summary>
 /// Unregister action and remove it from all controls.
 /// </summary>
 /// <param name="action"></param>
 internal void UnregisterAction(MetaAction action)
 {
     actions.Remove(action);
 }
 internal void RegisterAction(MetaAction action)
 {
     actions.Add(action);
 }
 public IEnumerable<Control> GetControls(MetaAction metaAction)
 {
     return controlAction.Where(it => Equals(it.Item1, metaAction)).Select(it =>
     {
         Control c;
         if (it.Item2.TryGetTarget(out c))
         {
             return c;
         }
         // if failed to get reference target
         return null;
     }).Where(it => it != null).ToArray();
 }
        public void Detach(MetaAction metaAction, Control control)
        {
            ValidateType(control);

            BindingOperations.ClearBinding(control, UIElement.IsEnabledProperty);
            BindingOperations.ClearBinding(control, UIElement.VisibilityProperty);

            Message.SetAttach(control, string.Empty);

            // Shortcut
            if (metaAction.KeyBinding != null)
            {
                var window = GetWindow(control);
                if (window.InputBindings.Contains(metaAction.KeyBinding))
                {
                    window.InputBindings.Remove(metaAction.KeyBinding);
                }
            }
        }