Ejemplo n.º 1
0
        protected DelayBinding(BindingExpressionBase bindingExpression, DependencyObject bindingTarget, DependencyProperty bindingTargetProperty, TimeSpan delay)
        {
            _bindingExpression = bindingExpression;
            _delay = delay;

            // Subscribe to notifications for when the target property changes. This event handler will be 
            // invoked when the user types, clicks, or anything else which changes the target property
            _descriptor = DependencyPropertyDescriptor.FromProperty(bindingTargetProperty, bindingTarget.GetType());


            // Add support so that the Enter key causes an immediate commit


            bindingTarget.SaftyInvoke<FrameworkElement>(el =>
                                                            {
                                                                el.Loaded += OnBindingTargetLoaded;
                                                            });

            // Setup the timer, but it won't be started until changes are detected

            _timer = new DispatcherTimer();
            _timer.Tick += TimerTick;
            _timer.Interval = _delay;
        }
Ejemplo n.º 2
0
 public static void RemoveDraggingHandler(DependencyObject d, DraggingRoutedEventHandler handler)
 {
     d.SaftyInvoke<UIElement>(uie => uie.RemoveHandler(DraggingEvent, handler));
 }
Ejemplo n.º 3
0
 public static void RemoveSelectedHandler(DependencyObject d, RoutedEventHandler handler)
 {
     d.SaftyInvoke<UIElement>(uie => uie.RemoveHandler(SelectedEvent, handler));
 }
Ejemplo n.º 4
0
        private static void OnRegisterCommandBindingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            //sender.SaftyInvoke<UIElement>(el =>
            //                                  {
            //                                      var bindings = e.NewValue as CommandBindingCollection;
            //                                      if (bindings != null)
            //                                          el.CommandBindings.AddRange(bindings);
            //                                  });

            var bindings = e.NewValue as CommandBindingCollection;
            if (bindings == null)
                return;


            sender.SaftyInvoke<UIElement>(el =>
            {
                if (bindings.Count != el.CommandBindings.Count)
                {
                    foreach (CommandBinding binding in bindings)
                    {
                        if (el.CommandBindings.Contains(binding))
                            continue;
                        el.CommandBindings.Add(binding);
                    }
                }
            });

        }
Ejemplo n.º 5
0
 public static void RemoveEndEditHandler(DependencyObject d, CellEditRoutedEventHandler handler)
 {
     d.SaftyInvoke<UIElement>(uie => uie.RemoveHandler(EndEditEvent, handler));
 }