/// <summary> /// Sets the source binding and updates status. /// </summary> protected virtual void SetSource(bool propertyValueChanged) { var old = Source; var binding = GetBindingExpression(PropertyProperty); if (!ReferenceEquals(_oldBinding, binding) || !ReferenceEquals(_oldDataContext, this.DataContext) || !propertyValueChanged) { _oldDataContext = this.DataContext; _oldBinding = binding; if (binding != null) { if (binding.ParentBinding != null && binding.ParentBinding.Path != null) { BindingPath = binding.ParentBinding.Path.Path; } else { BindingPath = string.Empty; } Source = GetRealSource(binding.DataItem, BindingPath); if (BindingPath.IndexOf('.') > 0) { BindingPath = BindingPath.Substring(BindingPath.LastIndexOf('.') + 1); } } else { Source = null; BindingPath = string.Empty; } HandleSourceEvents(old, Source); UpdateState(); } }
public static System.Windows.Data.Binding GetForegroundBinding(this FrameworkElement element) { System.Windows.Data.BindingExpression expr = element.GetBindingExpression(GetForegroundProperty(element)); if (expr == null) { return(null); } return(expr.ParentBinding); }
private void CommitTextBoxWithFocus() { if (_textboxWithFocus == null) { return; } System.Windows.Data.BindingExpression expression = _textboxWithFocus.GetBindingExpression(TextBox.TextProperty); if (expression != null) { expression.UpdateSource(); } }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { if (value is null) { return(new ValidationResult(false, "This field must be filled in.")); } if (value is System.Windows.Data.BindingExpression) { System.Windows.Data.BindingExpression binding = value as System.Windows.Data.BindingExpression; object dataItem = binding.DataItem; string propertyName = binding.ParentBinding.Path.Path; object propertyValue = dataItem.GetType().GetProperty(propertyName).GetValue(dataItem, null); value = propertyValue; } return(string.IsNullOrWhiteSpace((value ?? "").ToString()) ? new ValidationResult(false, "This field must be filled in.") : ValidationResult.ValidResult); }
protected override void OnTextChanged(TextChangedEventArgs e) { // if the timer elapsed or text was changed by something besides a keystroke // fire base.OnTextChanged if (TimerElapsed || !KeysPressed) { TimerElapsed = false; KeysPressed = false; base.OnTextChanged(e); System.Windows.Data.BindingExpression be = GetBindingExpression(TextProperty); if (be != null && be.Status == System.Windows.Data.BindingStatus.Active) { be.UpdateSource(); } PreviousTextValue = Text; } _previousTextChangedEventArgs = e; }