예제 #1
0
        public IOptionsExpression <T> To(DependencyObject target)
        {
            BinderExpression.ExposeContext(this, c => {
                c.TargetObject = target;
            });

            return(this);
        }
예제 #2
0
        public IOptionsExpression <T> On(DependencyProperty property)
        {
            BinderExpression.ExposeContext(this, c => {
                c.TargetProperty = property;
            });

            return(this);
        }
예제 #3
0
        private void ConfigureBinding <TBinding>(
            Action <TBinding> configurationAction
            ) where TBinding : BindingBase
        {
            BinderExpression.ExposeContext(this, c => {
                TBinding casted = c.Binding as TBinding;
                if (casted == null)
                {
                    throw new InvalidOperationException(ExceptionTexts.OperationInvalidForBindingType);
                }

                configurationAction(casted);
            });
        }
예제 #4
0
        public static IOptionsExpression <T> KeyGesture <T>(
            this IOptionsExpression <T> expression,
            Key key,
            ModifierKeys modifiers = ModifierKeys.None
            ) where T : ICommand
        {
            KeyGesture   gesture = CustomKeyGesture.Create(key, modifiers);
            InputBinding binding = new KeyBinding {
                Gesture = gesture
            };

            BinderExpression.ExposeContext(
                expression,
                ctx => {
                BindingOperations.SetBinding(binding, KeyBinding.CommandProperty, ctx.Binding);

                var targetUIElement      = ctx.TargetObject as UIElement;
                var targetContentElement = ctx.TargetObject as ContentElement;

                if (targetUIElement != null)
                {
                    targetUIElement.InputBindings.Add(binding);
                }
                else if (targetContentElement != null)
                {
                    targetContentElement.InputBindings.Add(binding);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
                );

            return(expression);
        }