示例#1
0
            public ObjectValidationRule(DependencyObject dependencyObject, DependencyProperty dependencyProperty, UpdateSourceTrigger updateSourceTrigger, Binding binding)
            {
                this.ValidationStep           = ValidationStep.UpdatedValue;
                this.ValidatesOnTargetUpdated = true;

                this.dependencyObject   = dependencyObject;
                this.dependencyProperty = dependencyProperty;

                //Set notification if target is changed (i.e. WPF control is updated with new value) to be able to re-register to validation change notifications
                binding.NotifyOnTargetUpdated   = true;
                binding.NotifyOnValidationError = true;
                Binding.AddTargetUpdatedHandler(dependencyObject, this.TargetUpdated);

                //Register for eception handling
                binding.UpdateSourceExceptionFilter = ObjectValidationRule.HandleSourceUpdateException;


                //Special handling for text boxes; only apply if not validated on every change
                if (updateSourceTrigger != UpdateSourceTrigger.PropertyChanged && dependencyObject is TextBoxBase)
                {
                    TextBoxBase TextBox = (TextBoxBase)dependencyObject;
                    TextBox.TextChanged += this.HandleTextChanged;
                }

                //Special handling to work around the error template disappearing
                if (this.dependencyObject is UIElement)
                {
                    ((UIElement)this.dependencyObject).IsVisibleChanged += this.ObjectValidationRule_IsVisibleChanged;
                }
                if (this.dependencyObject is UIElement3D)
                {
                    ((UIElement3D)this.dependencyObject).IsVisibleChanged += this.ObjectValidationRule_IsVisibleChanged;
                }
            }
 protected override void OnAttached()
 {
     base.OnAttached();
     targetUpdatedHandler = new EventHandler <DataTransferEventArgs>(TextBlockBindingUpdated);
     Binding.AddTargetUpdatedHandler(this.AssociatedObject, targetUpdatedHandler);
     // Run the initial behaviour logic
     HighlightTextBlock(this.AssociatedObject);
 }
        private static void OnTextCasingChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            var textBlock = obj as TextBlock;

            if (textBlock == null)
            {
                return;
            }

            SetText(textBlock, (TextCasing)args.NewValue);
            Binding.AddTargetUpdatedHandler(textBlock, (s, e) => SetText(textBlock, (TextCasing)args.NewValue));
        }
        /// <summary>
        /// Called after the behavior is attached into the associated object.
        /// </summary>
        protected override void OnAttached()
        {
            base.OnAttached();

            AssociatedObject.PreviewKeyDown             += HandlePreviewKeyDown;
            AssociatedObject.GotKeyboardFocus           += SelectAllText;
            AssociatedObject.MouseDoubleClick           += SelectAllText;
            AssociatedObject.PreviewMouseLeftButtonDown += SelectivelyIgnoreMouseButton;
            AssociatedObject.PreviewTextInput           += HandlePreviewTextInput;
            DataObject.AddPastingHandler(AssociatedObject, HandlePaste);

            AddBindingNotification();
            Binding.AddTargetUpdatedHandler(AssociatedObject, HandleTargetUpdated);
        }
 private static void TargetUpdatedCommand_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue != null)
     {
         if (e.OldValue == null)
         {
             Binding.AddTargetUpdatedHandler(d, DependencyProperty_TargetUpdated);
         }
         else
         {
             Binding.RemoveTargetUpdatedHandler(d, DependencyProperty_TargetUpdated);
         }
     }
 }
示例#6
0
        protected override void OnAttached()
        {
            base.OnAttached();

            AnimationOut            = new DoubleAnimation(1, 0, AnimationDuration, FillBehavior.HoldEnd);
            AnimationIn             = new DoubleAnimation(0, 1, AnimationDuration, FillBehavior.HoldEnd);
            AnimationOut.Completed += (sOut, eOut) =>
            {
                AssociatedObject.SetCurrentValue(TextBlock.TextProperty, NewValue);
                OldValue = NewValue;
                AssociatedObject.BeginAnimation(TextBlock.OpacityProperty, AnimationIn);
            };

            Binding.AddTargetUpdatedHandler(AssociatedObject, new EventHandler <DataTransferEventArgs>(Updated));
        }
        protected override void OnAttached()
        {
            base.OnAttached();

            m_animationIn             = new DoubleAnimation(1, AnimationDuration, FillBehavior.HoldEnd);
            m_animationOut            = new DoubleAnimation(0, AnimationDuration, FillBehavior.HoldEnd);
            m_animationOut.Completed += (sender, args) =>
            {
                AssociatedObject.SetCurrentValue(Border.VisibilityProperty, Visibility.Collapsed);
            };

            AssociatedObject.SetCurrentValue(Border.VisibilityProperty,
                                             InitialState == Visibility.Collapsed
                                                ? Visibility.Collapsed
                                                : Visibility.Visible);

            Binding.AddTargetUpdatedHandler(AssociatedObject, Updated);
        }
示例#8
0
    //Override to make the changes public.
    protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
    {
        base.OnVisualChildrenChanged(visualAdded, visualRemoved);
        //Create bindings here to properties you need to monitor for changes.
        //This example shows how to listen for changes to the Fill property.
        //You may need to add more bindings depending on your needs.
        Binding binding = new Binding("Fill");

        binding.Source = visualAdded;
        binding.NotifyOnTargetUpdated = true;
        binding.UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged;
        SetBinding(Shape.FillProperty, binding);
        //Instruct binding target updates to cause a global property
        //update for the ObservableCanvas.
        //This will make child property changes visible to the outside world.
        Binding.AddTargetUpdatedHandler(this,
                                        new EventHandler <DataTransferEventArgs>((object sender, DataTransferEventArgs e) =>
        {
            RaisePropertyChanged("Fill");
        }));
        //Notify listeners that the ObservableCanvas had an item added/removed.
        RaiseVisualChildrenChanged();
    }
示例#9
0
        public MainWindow()
        {
            VisualDiagnostics.EnableVisualTreeChanged();
            VisualDiagnostics.VisualTreeChanged += VisualDiagnosticsOnVisualTreeChanged;

            InitializeComponent();

            Binding.AddTargetUpdatedHandler(this, Handler);
            PrimaryRibbonModel model = new PrimaryRibbonModel();
            var modelTab             = new RibbonModelTab {
                Header = "Tab 1"
            };

            model.RibbonItems.Add(modelTab);
            var group1 = new RibbonModelGroup {
                Label = "Group 1"
            };
            // var modelControlGroup = new RibbonModelControlGroup();
            // modelControlGroup.Items.Add(new RibbonModelButton() { Label = "Click me" });
            // modelControlGroup.Items.Add(new RibbonModelButton() { Label = "Click me toos" });
            var insertFruitcommand = TryFindResource("InsertFruitCommand") as ICommand;
            var group2             = new RibbonModelGroup {
                Label = "Fruit"
            };

            var modelButton = new RibbonModelButton()
            {
                Label = "Strawberry", LargeImageSource = TryFindResource("Strawberry")
            };

            modelButton.Command          = insertFruitcommand;
            modelButton.CommandTarget    = this;
            modelButton.CommandParameter = modelButton;
            group2.Items.Add(modelButton);
            var modelItem = new RibbonModelButton
            {
                Label = "Grapes", LargeImageSource = TryFindResource("Grapes"), Command = insertFruitcommand
            };

            modelItem.CommandParameter = modelItem;
            group2.Items.Add(modelItem);
            modelItem.CommandTarget = this;
            var button = new RibbonModelButton()
            {
                Label = "Watermelon", LargeImageSource = TryFindResource("Watermelon")
            };

            button.Command          = insertFruitcommand;
            button.CommandTarget    = this;
            button.CommandParameter = button;
            group2.Items.Add(button);
            var comboBox = new RibbonModelItemComboBox()
            {
                Label = "Fruit dropdown"
            };
            var modelGallery = new RibbonModelGallery();

            var modelGalleryCategory = CreateFruitGalleryCategory();

            modelGallery.Items.Add(modelGalleryCategory);


            CommandBindings.Add(new CommandBinding(insertFruitcommand, Executed));

            var cat1 = CreateFruitGalleryCategory();

            cat1.Command       = insertFruitcommand;
            cat1.CommandTarget = this;
            RibbonModelItemMenuButton FruitButton = new RibbonModelItemMenuButton()
            {
                Label = "Fruit Selector"
            };
            var gallery = new RibbonModelGallery();

            gallery.Items.Add(cat1);
            FruitButton.ItemsCollection.Add(gallery);

            group1.Items.Add(FruitButton);
            comboBox.Items.Add(modelGallery);
            group1.Items.Add(comboBox);
            // group1.Items.Add(modelControlGroup);
            modelTab.ItemsCollection.Add(group1);
            modelTab.ItemsCollection.Add(group2);
            DataContext = model;
        }
 public MateriauxSelection() : base()
 {
     InitializeComponent();
     Binding.AddTargetUpdatedHandler(ListBox, ListBoxUpdated);
 }
 public VoltageReader()
 {
     InitializeComponent();
     Binding.AddTargetUpdatedHandler(ReaderValue, ReaderHandler);
 }
 private void DataBindingModeWindow_Loaded(object sender, RoutedEventArgs e)
 {
     Binding.AddSourceUpdatedHandler(TBoxResult, new EventHandler <DataTransferEventArgs>((sender1, e1) => { /*更新数据源被触发*/ }));
     Binding.AddTargetUpdatedHandler(TBoxResult, new EventHandler <DataTransferEventArgs>((sender1, e1) => { /*更新控件数据被触发*/ }));
 }
示例#13
0
 public FormesSelection()
 {
     InitializeComponent();
     Binding.AddTargetUpdatedHandler(ListBox, ListBoxUpdated);
 }