Exemplo n.º 1
0
        public void SetUp()
        {
            _comboBox = new ComboBox();
            _comboBox.SetValue(UndoManager.UndoScopeNameProperty, "ScopeName");
            _fakeVm = new FakeVm();
            var selected = new Binding("SelectedEnum")
            {
                Source = _fakeVm,
                UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
                NotifyOnSourceUpdated = true,
                NotifyOnTargetUpdated = true,
                Mode = BindingMode.TwoWay
            };
            BindingOperations.SetBinding(_comboBox, Selector.SelectedItemProperty, selected);

            var itemsSource = new Binding("EnumValues")
            {
                Source = _fakeVm,
                UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
                NotifyOnSourceUpdated = true,
                NotifyOnTargetUpdated = true,
                Mode = BindingMode.OneWay
            };
            BindingOperations.SetBinding(_comboBox, ItemsControl.ItemsSourceProperty, itemsSource);
            _comboBox.DataContext = _fakeVm;
            _undoManager = UndoManager.GetUndoManager(_comboBox);
        }
Exemplo n.º 2
0
 public void SetUp()
 {
     _textBox = new TextBox();
     _textBox.SetValue(UndoManager.UndoScopeNameProperty, "ScopeName");
     _fakeVm = new FakeVm();
     var binding = new Binding("Value")
     {
         Source = _fakeVm,
         UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
         NotifyOnSourceUpdated = true,
         NotifyOnTargetUpdated = true,
         Mode = BindingMode.TwoWay
     };
     BindingOperations.SetBinding(_textBox, TextBox.TextProperty, binding);
     _textBox.DataContext = _fakeVm;
     _undoManager = UndoManager.GetUndoManager(_textBox);
 }
Exemplo n.º 3
0
        private static void OnUseGlobalUndoRedoScopeChanged(DependencyObject o, DependencyPropertyChangedEventArgs args)
        {
            if (args.OldValue != null || args.NewValue == null)
            {
                return;
                throw new NotImplementedException("Changing scopes not implemented");
            }
            var scopeName = (string)args.NewValue;
            UndoManager manager;
            if (!UndoManagers.TryGetValue(scopeName, out manager))
            {
                manager = new UndoManager();
                UndoManagers.Add(scopeName, manager);
            }
            var uiElement = o as UIElement;
            if (uiElement != null)
            {
                ((UIElement)o).AddHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(manager.ExecutedHandler));
                ((UIElement)o).AddHandler(CommandManager.PreviewCanExecuteEvent, new CanExecuteRoutedEventHandler(manager.CanExecuteHandler));
            }
            var textBox = o as TextBox;
            if (textBox != null)
            {
                manager._controls.Add(textBox);
                textBox.DataContextChanged += (sender, _) => Subscribe((TextBoxBase)sender, TextBox.TextProperty);
            }
            var toggleButton = o as ToggleButton;
            if (toggleButton != null)
            {
                manager._controls.Add(toggleButton);
                toggleButton.DataContextChanged += (sender, _) => Subscribe((ToggleButton)sender, ToggleButton.IsCheckedProperty);
            }

            var selector = o as Selector;
            if (selector != null)
            {
                manager._controls.Add(selector);
                selector.DataContextChanged += (sender, _) => Subscribe((Selector)sender, Selector.SelectedItemProperty);
            }
        }