예제 #1
0
        /// <summary>
        /// Before insert data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataAccess_OnBeforeInsert(object sender, Custom.OperationArgs e)
        {
            // Get the binding source data
            BindingExpression bindingExpression = BindingOperations.GetBindingExpression(txtVendorDetailsID, TextBox.TextProperty);

            DataAccess.NequeoCompany.Data.VendorDetails data = (DataAccess.NequeoCompany.Data.VendorDetails)bindingExpression.DataItem;
            dataAccess.DataModel = data;

            MessageBoxResult result = MessageBox.Show("Are you sure you wish to insert this record?", "Insert", MessageBoxButton.YesNo);

            if (result != MessageBoxResult.Yes)
            {
                e.Cancel = true;
            }
        }
 /// <summary>
 /// キーダウン時のプレビューでKey.Enterを検出してUpdate
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnPreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         // エンターキーが押されたら BindingをUpdateする
         TextBox            tBox = (TextBox)sender;
         DependencyProperty prop = TextBox.TextProperty;
         BindingExpression  binding
             = BindingOperations.GetBindingExpression(tBox, prop);
         if (binding != null)
         {
             binding.UpdateSource();
         }
     }
 }
        /// <summary>
        /// given a dependency object and a dependency property, returns value indicating whether the property is currently bound.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool isBound = !_valueWhenBound;

            if (value is DependencyObject && parameter is DependencyProperty)
            {
                BindingExpression bindingExpr = BindingOperations.GetBindingExpression(value as DependencyObject, parameter as DependencyProperty);
                if (bindingExpr != null && bindingExpr.ResolvedSource != null)
                {
                    isBound = _valueWhenBound;
                }
            }

            return(isBound);
        }
        }         // event Control_KeyUpHandler

        private void Control_GotKeyboardFocusHandler(object sender, KeyboardFocusChangedEventArgs e)
        {
            if (e.NewFocus is TextBox newTextBox)
            {
                var b    = BindingOperations.GetBinding(newTextBox, TextBox.TextProperty);
                var expr = BindingOperations.GetBindingExpression(newTextBox, TextBox.TextProperty);
                if (b != null && (b.UpdateSourceTrigger == UpdateSourceTrigger.Default || b.UpdateSourceTrigger == UpdateSourceTrigger.LostFocus) && expr.Status != BindingStatus.PathError)
                {
                    currentBindingExpression = expr;
#if DEBUG && NOTIFY_BINDING_SOURCE_UPDATE
                    Debug.Print("Textbox GotFocus");
#endif
                }
            }
        }         // event Control_GotKeyboardFocusHandler
        private void OnKeyPressedDown(object sender, KeyEventArgs e)
        {
            var bindingExpression = BindingOperations.GetBindingExpression((TextBox)sender, TextBox.TextProperty);

            if (e.Key == Key.Enter)
            {
                bindingExpression?.UpdateSource();
                Mode = Mode.BreadCrumbs;
            }
            if (e.Key == Key.Escape)
            {
                bindingExpression?.UpdateTarget();
                Mode = Mode.BreadCrumbs;
            }
        }
예제 #6
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            Loaded -= OnLoaded;

            if (BindingOperations.GetBindingExpression(this, FormattedTextProperty) == null &&
                BindingOperations.GetMultiBindingExpression(this, FormattedTextProperty) == null)
            {
                SetBinding(FormattedTextProperty, new Binding {
                    Path = new PropertyPath("Text"), Source = this
                });
            }

            DataContextChanged += OnDataContextChanged;
            OnDataContextChanged(null, new DependencyPropertyChangedEventArgs());
        }
예제 #7
0
        private void TextBox_KeyUp_UpdateBinding(object sender, KeyEventArgs e)
        {
            //update binding on enter pressed
            if (e.Key == Key.Enter)
            {
                TextBox            tBox = (TextBox)sender;
                DependencyProperty prop = TextBox.TextProperty;

                BindingExpression binding = BindingOperations.GetBindingExpression(tBox, prop);
                if (binding != null)
                {
                    binding.UpdateSource();
                }
            }
        }
    protected override void OnThumbDragStarted(DragStartedEventArgs e)
    {
        base.OnThumbDragStarted(e);
        var expression = BindingOperations.GetBindingExpression(this, ValueProperty);

        if (expression != null)
        {
            SupressedBinding = expression.ParentBinding;
            //clearing the binding will cause the Value to reset to default,
            //so we'll need to restore it
            var value = Value;
            BindingOperations.ClearBinding(this, ValueProperty);
            SetValue(ValueProperty, value);
        }
    }
 private void DateTimePicker_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (Keyboard.Modifiers == ModifierKeys.None && e.Key == Key.Escape)
     {
         var picker = sender as Xceed.Wpf.Toolkit.DateTimePicker;
         var be     = BindingOperations.GetBindingExpression(picker, Xceed.Wpf.Toolkit.DateTimePicker.ValueProperty);
         picker.CommitInput();
         be.UpdateTarget();
     }
     else if (e.Key == Key.Tab)
     {
         var picker = sender as Xceed.Wpf.Toolkit.DateTimePicker;
         picker.CommitInput();
     }
 }
예제 #10
0
 // If key being pressed is the Enter key, and EnterUpdatesTextSource is set to true, then update source for Text property
 private static void OnPreviewKeyDown_UpdateSourceIfEnter(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         if (GetEnterUpdatesTextSource((DependencyObject)sender))
         {
             var obj = sender as UIElement;
             BindingExpression textBinding = BindingOperations.GetBindingExpression(
                 obj, TextBox.TextProperty);
             if (textBinding != null)
             {
                 textBinding.UpdateSource();
             }
         }
     }
 }
예제 #11
0
 protected virtual void SetIncremented(T value)
 {
     _ = Keyboard.Focus(this);
     this.SetTextAndCreateUndoAction(value.ToString(this.Culture));
     this.UpdateFormattedText(value);
     if (this.SpinUpdateMode == SpinUpdateMode.PropertyChanged)
     {
         if (BindingOperations.GetBindingExpression(this, ValueProperty) is { ParentBinding : { } binding } expression&&
             binding.Mode.IsEither(BindingMode.TwoWay, BindingMode.Default) &&
             binding.UpdateSourceTrigger.IsEither(UpdateSourceTrigger.Default, UpdateSourceTrigger.LostFocus))
         {
             this.UpdateValidation();
             expression.UpdateSource();
         }
     }
 }
예제 #12
0
        private void TextBox_KeyEnterUpdate(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter || e.Key == Key.Return)
            {
                TextBox tBox = (TextBox)sender;

                DependencyProperty prop = TextBox.TextProperty;

                BindingExpression binding = BindingOperations.GetBindingExpression(tBox, prop);

                if (binding != null)
                {
                    SearchButton_Click(sender, e);
                }
            }
        }
예제 #13
0
        /// <summary>
        /// キーが押されたときに呼ばれます。
        /// </summary>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Key == Key.Enter)
            {
                var bindingExpression =
                    BindingOperations.GetBindingExpression(
                        this, TextProperty);

                if (bindingExpression != null)
                {
                    bindingExpression.UpdateSource();
                }
            }
        }
예제 #14
0
        private static void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                UIElement          element  = e.Source as UIElement;
                DependencyProperty property =
                    (DependencyProperty)element.GetValue(BindOnEnterProperty);

                BindingExpression binding =
                    BindingOperations.GetBindingExpression(element, property);
                if (binding != null)
                {
                    binding.UpdateSource();
                }
            }
        }
예제 #15
0
        private void OnKeyUp(object sender, KeyEventArgs e)
        {
            // update property on enter
            if (e.Key != Key.Enter)
            {
                base.OnKeyUp(e);
                e.Handled = true;
                return;
            }

            e.Handled = true;
            var binding = BindingOperations.GetBindingExpression(this, ValueProperty);

            binding?.UpdateSource();
            Keyboard.ClearFocus();
        }
예제 #16
0
        /// <summary>
        /// Clears the given FrameworkElement from all ValidationErrors created using the
        /// DummyRule's MarkInvalid(...) method and removes the binding to the DummyErrorProperty.
        /// </summary>
        /// <param name="frameworkElement">The framework element the errors are removed from.</param>
        /// <exception cref="ArgumentNullException" />
        public static void ClearInvalid(FrameworkElement frameworkElement)
        {
            if (frameworkElement == null)
            {
                throw new ArgumentNullException("Argument 'frameworkElement' must not be null.");
            }

            BindingExpression bindex = BindingOperations.GetBindingExpression(frameworkElement, DummyRule.DummyErrorProperty);

            if (bindex != null)
            {
                Validation.ClearInvalid(bindex);

                BindingOperations.ClearBinding(frameworkElement, DummyRule.DummyErrorProperty);
            }
        }
예제 #17
0
        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);
            if (this.SelectedIndex == -1)
            {
                return;
            }
            this.Selection = this.SelectedItem;
            BindingExpression bindingExpression = BindingOperations.GetBindingExpression((DependencyObject)this, OnDemandComboBox.SelectionProperty);

            if (bindingExpression == null)
            {
                return;
            }
            bindingExpression.UpdateTarget();
        }
예제 #18
0
        // changes GUI at program stop event
        private void programStopChangeGui()
        {
            // listbox remove selected index binding
            bindingExpressions.Remove(BindingOperations.GetBindingExpression(this.listBoxProgram, ListBox.SelectedIndexProperty));
            BindingOperations.ClearBinding(listBoxProgram, ListBox.SelectedIndexProperty);

            this.buttonProgramStart.Content          = "Start";
            this.buttonProgramAdd.Content            = "Add";
            this.buttonProgramDown.IsEnabled         = true;
            this.buttonProgramRemove.IsEnabled       = true;
            this.buttonProgramUp.IsEnabled           = true;
            this.tabControlProgram.IsEnabled         = true;
            this.menuItemExperimentAdd.IsEnabled     = true;
            this.menuItemExperimentReplace.IsEnabled = true;
            this.labelElapsed.Visibility             = Visibility.Hidden;
        }
예제 #19
0
        private static void CheckBox_Checked_Add(object sender, RoutedEventArgs e)
        {
            var checkBox         = (CheckBox)e.OriginalSource;
            var parentNode       = (XElement)checkBox.DataContext;
            var frameworkElement = (FrameworkElement)e.Source;
            var nodeName         = GetAddXElementIfNotExistsRemoveEmpty(frameworkElement);

            if (parentNode.Element(nodeName) == null)
            {
                parentNode.Add(new XElement(nodeName)
                {
                    Value = checkBox.IsChecked == null ? "" : (checkBox.IsChecked == true ? "true" : "false")
                });
                BindingOperations.GetBindingExpression(frameworkElement, CheckBox.IsCheckedProperty).UpdateTarget();
            }
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (ParentTreeView?.SelectedItems != null && ParentTreeView.SelectedItems.Contains(DataContext))
            {
                if (BindingOperations.GetBindingExpression(this, IsSelectedProperty)?.ParentBinding?.Mode == BindingMode.OneWay)
                {
                    ParentTreeView.Selection?.SelectFromProperty(this, false);
                }
                else
                {
                    IsSelected = true;
                }
            }
        }
예제 #21
0
        private void OnTextChanged(object sender, TextChangedEventArgs e)
        {
            if (BindingOperations.IsDataBound(this, FileNameProperty))
            {
                BindingManager.SetValue(BindingOperations.GetBindingExpression(this, FileNameProperty), tbxPath.Text);
            }
            else
            {
                FileName = tbxPath.Text;
            }

            e.Handled = true;
            RoutedEventArgs args = new RoutedEventArgs(FileNameChangedEvent);

            RaiseEvent(args);
        }
        private void TextBox_KeyEnterUpdate(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                TextBox            tBox = ( TextBox )sender;
                DependencyProperty prop = TextBox.TextProperty;

                BindingExpression binding = BindingOperations.GetBindingExpression(tBox, prop);
                if (binding != null)
                {
                    binding.UpdateSource();
                }

                Keyboard.ClearFocus();
            }
        }
예제 #23
0
 private static void OnFreezableChanged(object sender, EventArgs e)
 {
     if (sender is Freezable freezable)
     {
         var bindingProperty   = GetBindingProperty(freezable);
         var bindingExpression = BindingOperations.GetBindingExpression(freezable, bindingProperty);
         if (bindingExpression != null)
         {
             freezable.Changed -= OnFreezableChanged;
             bindingExpression.UpdateTarget();
             freezable.SetValue(bindingProperty, freezable.GetValue(bindingProperty));
             BindingOperations.ClearAllBindings(freezable);
             freezable.Freeze();
         }
     }
 }
예제 #24
0
        private void Filter_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return;
            }
            var tBox = (TextBox)sender;
            var prop = TextBox.TextProperty;

            var binding = BindingOperations.GetBindingExpression(tBox, prop);

            if (binding != null)
            {
                binding.UpdateSource();
            }
        }
 private void OnTick(object sender, EventArgs e)
 {
     if (!_timerStoped)
     {
         var bindingExpression = BindingOperations.GetBindingExpression(AssociatedObject, DependencyProperty);
         if (bindingExpression != null)
         {
             bindingExpression?.UpdateTarget();
         }
         else
         {
             var mbe = BindingOperations.GetMultiBindingExpression(AssociatedObject, DependencyProperty);
             mbe?.UpdateTarget();
         }
     }
 }
예제 #26
0
        private void KeyDownHandler(Object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && AssociatedObject.IsKeyboardFocusWithin)
            {
                var binding = BindingOperations.GetBindingExpression(AssociatedObject, TextBox.TextProperty);
                if (binding == null)
                {
                    return;
                }

                binding.UpdateSource();
                bindingWasUpdated = true;

                Keyboard.ClearFocus();
            }
        }
        private static void checkErrors(DependencyObject parent)
        {
            LocalValueEnumerator localValues = parent.GetLocalValueEnumerator();

            while (localValues.MoveNext())
            {
                LocalValueEntry entry = localValues.Current;
                if (BindingOperations.IsDataBound(parent, entry.Property))
                {
                    BindingExpression binding =
                        BindingOperations.GetBindingExpression(parent, entry.Property);

                    if (binding == null || // Not possible because of IsDataBound() check, but we leave it here to remove the warning
                        binding.DataItem == null)
                    {
                        continue;
                    }

                    if (binding.Status == BindingStatus.PathError)
                    {
                        var element = parent as FrameworkElement;
                        if (element != null)
                        {
                            var elementAdornerLayer = AdornerLayer.GetAdornerLayer(element);
                            if (elementAdornerLayer == null)
                            {
                                continue;
                            }

                            Adorner[] adorners = elementAdornerLayer.GetAdorners(element);
                            if (adorners != null)
                            {
                                foreach (Adorner a in adorners)
                                {
                                    if (a is BindingErrorBorderAdorner)
                                    {
                                        continue;
                                    }
                                }
                            }

                            elementAdornerLayer.Add(new BindingErrorBorderAdorner(element));
                        }
                    }
                }
            }
        }
예제 #28
0
        private void EnterTextBoxPreviewKeyDown(object sender, KeyEventArgs e)
        {
            // Below is some horrible WPF code so that
            // when we press the ENTER key on the project path, it will update its binding.
            if (e.Key == Key.Return)
            {
                // Get the DependencyProperty.
                var prop = TextBox.TextProperty;

                // Now, get the binding and update it if possible.
                BindingExpression be = BindingOperations.GetBindingExpression(ProjPath, prop);
                if (be != null)
                {
                    be.UpdateSource();
                }
            }
        }
예제 #29
0
        /// <summary>
        /// Handles the LostFocus event of the BindableRichTextBox control.
        /// </summary>
        /// <param title="sender">The source of the event.</param>
        /// <param title="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        void BindableRichTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            // If we have a binding that is set for LostFocus or Default (which we are specifying as default)
            // then update the source.
            Binding binding = BindingOperations.GetBinding(this, DocumentProperty);

            if (binding == null)
            {
                return;
            }
            if (binding.UpdateSourceTrigger == UpdateSourceTrigger.Default ||
                binding.UpdateSourceTrigger == UpdateSourceTrigger.LostFocus ||
                binding.UpdateSourceTrigger == UpdateSourceTrigger.PropertyChanged)
            {
                BindingOperations.GetBindingExpression(this, DocumentProperty).UpdateSource();
            }
        }
        public void DataItemIsByDefault()
        {
            var target  = new BindingTestTarget();
            var binding = new Binding("SourceProperty")
            {
                Mode = BindingMode.TwoWay
            };

            BindingOperations.SetBinding(target, BindingTestTarget.TargetPropertyProperty, binding);

            Assert.IsNull(target.TargetProperty);

            var bindingExpression = BindingOperations.GetBindingExpression(target, BindingTestTarget.TargetPropertyProperty);

            Assert.IsNull(bindingExpression.DataItem);
            Assert.AreEqual("SourceProperty", bindingExpression.ParentBinding.Path.Path);
        }