private void BindingTarget_KeyUp(object sender, KeyEventArgs e) { if (e.Key != Key.Enter) { return; } _timer.Stop(); _bindingExpression.UpdateSource(); }
private void UpdateSelectedSource(BindingExpressionBase be, string propName, bool selectAll = false) { be.UpdateSource(); if (selectAll) { switch (propName) { case "Left": LeftEdit.SelectAll(); break; case "Top": TopEdit.SelectAll(); break; case "Width": WidthEdit.SelectAll(); break; case "Height": HeightEdit.SelectAll(); break; } } _selfig.Parent.UpdateSelected(); }
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ComparisonValue comparisonValue = (ComparisonValue)d; BindingExpressionBase bindingExpressionBase = BindingOperations.GetBindingExpressionBase(comparisonValue, BindingToTriggerProperty); bindingExpressionBase?.UpdateSource(); }
private static void OnKeyDown(KeyEventArgs e, BindingExpressionBase binding) { if (e.Key.Equals(Key.Return)) { binding.UpdateSource(); } }
// Token: 0x060085B9 RID: 34233 RVA: 0x0024A67C File Offset: 0x0024887C private void SourceDoDragDrop(ITextSelection selection, IDataObject dataObject) { DragDropEffects dragDropEffects = DragDropEffects.Copy; if (!this._textEditor.IsReadOnly) { dragDropEffects |= DragDropEffects.Move; } DragDropEffects dragDropEffects2 = DragDropEffects.None; try { dragDropEffects2 = DragDrop.DoDragDrop(this._textEditor.UiScope, dataObject, dragDropEffects); } catch (COMException ex) when(ex.HResult == -2147418113) { } if (!this._textEditor.IsReadOnly && dragDropEffects2 == DragDropEffects.Move && this._dragSourceTextRange != null && !this._dragSourceTextRange.IsEmpty) { using (selection.DeclareChangeBlock()) { this._dragSourceTextRange.Text = string.Empty; } } this._dragSourceTextRange = null; if (!this._textEditor.IsReadOnly) { BindingExpressionBase bindingExpressionBase = BindingOperations.GetBindingExpressionBase(this._textEditor.UiScope, TextBox.TextProperty); if (bindingExpressionBase != null) { bindingExpressionBase.UpdateSource(); bindingExpressionBase.UpdateTarget(); } } }
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ManagedActivityContext context = (ManagedActivityContext)d; BindingExpressionBase bindingExpressionBase = BindingOperations.GetBindingExpressionBase(context, BindingToTriggerProperty); bindingExpressionBase?.UpdateSource(); }
protected virtual void EhTextChanged(object sender, EventArgs e) { _isInitialTextModified = true; if (IsValidatingOnEveryTextChange) { _bindingExToValidatedText?.UpdateSource(); } }
/// <summary> /// Updates the source according to the specified property. /// </summary> /// <param name="o">The source.</param> /// <param name="prop">The property.</param> public static void UpdateSourceProperty(this DependencyObject o, DependencyProperty prop) { BindingExpressionBase exp = BindingOperations.GetBindingExpressionBase(o, prop); if (exp != null) { exp.UpdateSource(); } }
/// <summary> /// DragEnd event handler from DragDrop behavior. /// </summary> private void SourceDoDragDrop(ITextSelection selection, IDataObject dataObject) { // Run OLE drag-drop process. It will eat all user input until the drop DragDropEffects allowedDragDropEffects = DragDropEffects.Copy; if (!_textEditor.IsReadOnly) { allowedDragDropEffects |= DragDropEffects.Move; } DragDropEffects resultingDragDropEffects = DragDrop.DoDragDrop( // _textEditor.UiScope, // dragSource, dataObject, // allowedDragDropEffects); // Remove source selection if (!_textEditor.IsReadOnly && // resultingDragDropEffects == DragDropEffects.Move && // _dragSourceTextRange != null && !_dragSourceTextRange.IsEmpty) { // Normally we delete the source selection from OnDrop event, // unless source and target TextBoxes are different. // In this case the source selection is still not empty, // which means that target was in a different TextBox. // So we still need to delete the selected content in the source one. // This will create an undo unit different from a dropping one, // which is ok, because it will be in different TextBox's undo stack. using (selection.DeclareChangeBlock()) { // This is end of Move - we need to delete source content _dragSourceTextRange.Text = String.Empty; } } // Clean up the text range. _dragSourceTextRange = null; // Check the data binding expression and update the source and target if the drag source // has the binding expression. Without this, data binding is broken after complete the // drag-drop operation because Drop() paste the object then set the focus to the target. // The losting focus invoke the data binding expression's Update(), but the source isn't // updated yet before complete DoDragDrop. if (!_textEditor.IsReadOnly) { BindingExpressionBase bindingExpression = BindingOperations.GetBindingExpressionBase( _textEditor.UiScope, TextBox.TextProperty); if (bindingExpression != null) { bindingExpression.UpdateSource(); bindingExpression.UpdateTarget(); } } }
/// <summary> /// Updates the source according to the specified property. /// </summary> /// <param name="o">The source.</param> /// <param name="prop">The property.</param> public static void UpdateSourceProperty(this DependencyObject o, DependencyProperty prop) { ArgumentValidator.NotNull(o, "o"); ArgumentValidator.NotNull(prop, "prop"); BindingExpressionBase exp = BindingOperations.GetBindingExpressionBase(o, prop); if (exp != null) { exp.UpdateSource(); } }
public void EndEdit(bool confirm) { if (AdornedElement.IsEditing) { if (confirm) { mBinding.UpdateSource(); } AdornedElement.IsEditing = false; } Visibility = Visibility.Collapsed; }
public static void UpdateBindingSources(this DependencyObject dependencyObject) { foreach (DependencyObject element in dependencyObject.EnumerateVisualDescendents()) { LocalValueEnumerator localValueEnumerator = element.GetLocalValueEnumerator(); while (localValueEnumerator.MoveNext()) { BindingExpressionBase bindingExpression = BindingOperations.GetBindingExpressionBase(element, localValueEnumerator.Current.Property); bindingExpression?.UpdateSource(); } } }
protected override void OnKeyDown(KeyEventArgs e) { if (e.Key == Key.Return) { BindingExpressionBase expression = BindingOperations.GetBindingExpressionBase(this, EditTextBox.TextProperty); if (expression != null) { expression.UpdateSource(); } e.Handled = true; } base.OnKeyDown(e); }
/// <summary> /// Flushes all bindings for the specified <see cref="DependencyObject"/> and all of its descendents. /// </summary> /// <param name="dependencyObject">The dependency object.</param> //public static void FlushBindings (this DependencyObject dependencyObject) ** Uncomment when we have C# 3.0 support ** public static void FlushBindings(DependencyObject dependencyObject) { //foreach (DependencyObject element in dependencyObject.EnumerateVisualDescendents ()) ** Uncomment when we have C# 3.0 support ** foreach (DependencyObject element in Extensions.EnumerateVisualDescendents(dependencyObject)) { LocalValueEnumerator localValueEnumerator = element.GetLocalValueEnumerator(); while (localValueEnumerator.MoveNext()) { BindingExpressionBase bindingExpression = BindingOperations.GetBindingExpressionBase(element, localValueEnumerator.Current.Property); if (bindingExpression != null) { bindingExpression.UpdateSource(); bindingExpression.UpdateTarget(); } } } }
/// <summary> /// http://blogs.msdn.com/b/ryantrem/archive/2010/04/09/globally-updating-binding-sources-in-wpf.aspx /// </summary> private void UpdateActiveElementBindings() { if (Keyboard.FocusedElement != null && Keyboard.FocusedElement is DependencyObject) { DependencyObject element = (DependencyObject)Keyboard.FocusedElement; LocalValueEnumerator localValueEnumerator = element.GetLocalValueEnumerator(); while (localValueEnumerator.MoveNext()) { BindingExpressionBase bindingExpression = BindingOperations.GetBindingExpressionBase(element, localValueEnumerator.Current.Property); if (bindingExpression != null) { bindingExpression.UpdateSource(); bindingExpression.UpdateTarget(); } } } }
/// <summary> /// DragEnd event handler from DragDrop behavior. /// </summary> private void SourceDoDragDrop(ITextSelection selection, IDataObject dataObject) { // Run OLE drag-drop process. It will eat all user input until the drop DragDropEffects allowedDragDropEffects = DragDropEffects.Copy; if (!_textEditor.IsReadOnly) { allowedDragDropEffects |= DragDropEffects.Move; } DragDropEffects resultingDragDropEffects = DragDropEffects.None; try { resultingDragDropEffects = DragDrop.DoDragDrop( // _textEditor.UiScope, // dragSource, dataObject, // allowedDragDropEffects); } // DDVSO 685894: // Ole32's DoDragDrop can return E_UNEXCEPTED, which comes to us as a COMException, // if something unexpected happened during the drag and drop operation, // e.g. the application receiving the drop failed. In this case we should // not fail, we should catch the exception and act as if the drop wasn't allowed. catch (COMException ex) when(ex.HResult == NativeMethods.E_UNEXPECTED) { } // Remove source selection if (!_textEditor.IsReadOnly && // resultingDragDropEffects == DragDropEffects.Move && // _dragSourceTextRange != null && !_dragSourceTextRange.IsEmpty) { // Normally we delete the source selection from OnDrop event, // unless source and target TextBoxes are different. // In this case the source selection is still not empty, // which means that target was in a different TextBox. // So we still need to delete the selected content in the source one. // This will create an undo unit different from a dropping one, // which is ok, because it will be in different TextBox's undo stack. using (selection.DeclareChangeBlock()) { // This is end of Move - we need to delete source content _dragSourceTextRange.Text = String.Empty; } } // Clean up the text range. _dragSourceTextRange = null; // Check the data binding expression and update the source and target if the drag source // has the binding expression. Without this, data binding is broken after complete the // drag-drop operation because Drop() paste the object then set the focus to the target. // The losting focus invoke the data binding expression's Update(), but the source isn't // updated yet before complete DoDragDrop. if (!_textEditor.IsReadOnly) { BindingExpressionBase bindingExpression = BindingOperations.GetBindingExpressionBase( _textEditor.UiScope, TextBox.TextProperty); if (bindingExpression != null) { bindingExpression.UpdateSource(); bindingExpression.UpdateTarget(); } } }
private void TimerTick(object sender, EventArgs e) { _timer.Stop(); _bindingExpression.UpdateSource(); }
private static void OnLostFocus(BindingExpressionBase binding) { binding.UpdateSource(); }
public static bool CheckAllValidationErrors(DependencyObject dependencyObject, DependencyProperty dependencyProperty) { bool isValid = true; if (BindingOperations.IsDataBound(dependencyObject, dependencyProperty)) { Binding binding = BindingOperations.GetBinding(dependencyObject, dependencyProperty); MultiBinding multiBinding = null; if (binding == null) { multiBinding = BindingOperations.GetMultiBinding(dependencyObject, dependencyProperty); if (multiBinding == null) { return(true); } } if (binding != null && binding.ValidationRules.Count > 0 || multiBinding != null && multiBinding.ValidationRules.Count > 0) { BindingExpression bindingExpression = BindingOperations.GetBindingExpression(dependencyObject, dependencyProperty); MultiBindingExpression multiBindingExpression = null; if (bindingExpression == null) { multiBindingExpression = BindingOperations.GetMultiBindingExpression(dependencyObject, dependencyProperty); if (multiBindingExpression == null) { return(true); } } BindingExpressionBase expression = bindingExpression ?? (BindingExpressionBase)multiBindingExpression; switch (binding != null ? binding.Mode : multiBinding.Mode) { case BindingMode.OneTime: case BindingMode.OneWay: expression.UpdateTarget(); break; default: expression.UpdateSource(); break; } if (expression.HasError) { isValid = false; } } // Another method: foreach (ValidationRule rule in (binding != null ? binding.ValidationRules : multiBinding.ValidationRules)) { ValidationResult result = rule.Validate(dependencyObject.GetValue(dependencyProperty), null); if (!result.IsValid) { BindingExpression bindingExpression = BindingOperations.GetBindingExpression(dependencyObject, dependencyProperty); MultiBindingExpression multiBindingExpression = null; if (bindingExpression == null) { multiBindingExpression = BindingOperations.GetMultiBindingExpression(dependencyObject, dependencyProperty); if (multiBindingExpression == null) { continue; } } BindingExpressionBase expression = bindingExpression ?? (BindingExpressionBase)multiBindingExpression; System.Windows.Controls.Validation.MarkInvalid(expression, new ValidationError(rule, expression, result.ErrorContent, null)); isValid = false; } } } return(isValid); }