public GetBindingExpression ( |
||
dp | ||
리턴 | System.Windows.Data.BindingExpression |
protected override bool CommitCellEdit(System.Windows.FrameworkElement editingElement) { DatePicker dp = editingElement as DatePicker; if (dp == null) { return(true); } dp.Text = "01/01/2001"; //if (!isCellValueChanged) tb.Text = Convert.ToString(previouseCellValue); //if (MaxScale > 0 && FormatCellAfterCellEndEdit) //{ // if (Convert.ToString(tb.Text).Trim().Length == 0) tb.Text = "0"; // string decimalFormat = "0." + "".PadLeft(MaxScale, '0'); // tb.Text = Convert.ToDecimal(Convert.ToString(tb.Text)).ToString(decimalFormat); //} BindingExpression binding = editingElement.GetBindingExpression(DatePicker.TextProperty); if (binding != null) { binding.UpdateSource(); } return(true); //base.CommitCellEdit(editingElement); }
public static string ForceValidation(FrameworkElement ele) { string errMsg = ""; var validationprop = GetValidationProperty(ele); if (validationprop != null) { ele.GetBindingExpression(validationprop).UpdateSource(); if (Validation.GetHasError(ele)) { var errs = Validation.GetErrors(ele); foreach (var err in errs) { string errstr = null; if (err.ErrorContent != null) errstr = err.ErrorContent.ToString(); else if (err.Exception != null) errstr = err.Exception.Message; else errstr = "Unknown Error"; errMsg += errstr + "\n"; } } return errMsg; } var validationcb = GetValidationCallback(ele); if (validationcb != null) { return validationcb(); } throw new InvalidOperationException("Neither ValidationProperty nor ValidationCallback is set."); }
public static void RaiseValidationError(this FrameworkElement frameworkElement) { BindingExpression be = frameworkElement.GetBindingExpression(Control.TagProperty); if (be != null) { ((CustomizeValidation)be.DataItem).ShowErrorMessage = true; be.UpdateSource(); } }
static void ForceDataBind(FrameworkElement sender, DependencyProperty dependencyProperty) { lock (Timers) { if( Timers.ContainsKey(sender)) { var timer = Timers[sender]; timer.Stop(); sender.GetBindingExpression(dependencyProperty).UpdateSource(); } } }
/// <summary> /// Overides the configuration behavior. /// </summary> /// <param name="frameworkElement">The framework element.</param> /// <param name="targetElement">The target element.</param> /// <param name="property">The property.</param> internal static void OverideConfigurationBehavior( this FrameworkElement frameworkElement, FrameworkElement targetElement, DependencyProperty property ) { var bindingExpression = property == null ? null : targetElement.GetBindingExpression ( property ); if ( bindingExpression != null ) { var propertyName = bindingExpression.ParentBinding.Path.Path; frameworkElement.OverrideBehavior ( new ConfigurationBehavior { Metadata = string.IsNullOrWhiteSpace ( propertyName ) ? null : propertyName } ); } else if ( frameworkElement is IMetadataProvider || !string.IsNullOrWhiteSpace ( Configuration.GetMetaDataOveride ( frameworkElement ) ) ) { frameworkElement.OverrideBehavior ( new ConfigurationBehavior () ); } }
public static void UpdateBinding(FrameworkElement element, DependencyProperty property, UpdateBindingType updateType) { BindingExpression bindingExpression = element.GetBindingExpression(property); if (bindingExpression != null) { // If desired, push the current text value to the source of the binding. if (updateType == UpdateBindingType.Source || updateType == UpdateBindingType.Both) { bindingExpression.UpdateSource(); } // Update the text from the source of the binding. if (updateType == UpdateBindingType.Target || updateType == UpdateBindingType.Both) { bindingExpression.UpdateTarget(); } } }
internal static LabelValidationMetadata ParseMetadata(FrameworkElement element, bool forceUpdate, out object entity, out BindingExpression bindingExpression) { entity = (object)null; bindingExpression = (BindingExpression)null; if (element == null) return (LabelValidationMetadata)null; if (!forceUpdate) { LabelValidationMetadata validationMetadata = element.GetValue(LabelValidationHelper.ValidationMetadataProperty) as LabelValidationMetadata; if (validationMetadata != null) return validationMetadata; } foreach (FieldInfo fieldInfo in element.GetType().GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy)) { if (fieldInfo.FieldType == typeof(DependencyProperty)) { BindingExpression bindingExpression1 = element.GetBindingExpression((DependencyProperty)fieldInfo.GetValue((object)null)); if (bindingExpression1 != null && bindingExpression1.ParentBinding != null && bindingExpression1.ParentBinding.Path != null) { entity = bindingExpression1.DataItem ?? element.DataContext; if (entity != null) { if (bindingExpression1.ParentBinding.Mode == BindingMode.TwoWay) { bindingExpression = bindingExpression1; break; } else if (bindingExpression == null || string.Compare(bindingExpression1.ParentBinding.Path.Path, bindingExpression.ParentBinding.Path.Path, StringComparison.Ordinal) < 0) bindingExpression = bindingExpression1; } } } } if (bindingExpression == null) return null; LabelValidationMetadata validationMetadata1 = ParseMetadata(bindingExpression.ParentBinding.Path.Path, entity); element.SetValue(ValidationMetadataProperty, (object)validationMetadata1); return validationMetadata1; }
public static void FocusChildUsingBinding(FrameworkElement element) { if (element == null) throw new ArgumentNullException("element"); // for some reason, this binding does not work, but we still use it and do our own automatically BindingExpression expr = element.GetBindingExpression(FocusManager.FocusedElementProperty); if (expr != null && expr.ParentBinding != null && expr.ParentBinding.ElementName != null) { FrameworkElement child = element.FindFocusableVisualChild<FrameworkElement>(expr.ParentBinding.ElementName); if (child != null) { child.Focus(); } } }
/// We don't provide default Paste but this public method is exposed to help custom implementation of Paste /// <summary> /// This method stores the cellContent into the item object using ClipboardContentBinding. /// </summary> /// <param name="item"></param> /// <param name="cellContent"></param> public virtual void OnPastingCellClipboardContent(object item, object cellContent) { BindingBase binding = ClipboardContentBinding; if (binding != null) { // Raise the event to give a chance for external listeners to modify the cell content // before it gets stored into the cell if (PastingCellClipboardContent != null) { DataGridCellClipboardEventArgs args = new DataGridCellClipboardEventArgs(item, this, cellContent); PastingCellClipboardContent(this, args); cellContent = args.Content; } // Event handlers can cancel Paste of a cell by setting its content to null if (cellContent != null) { FrameworkElement fe = new FrameworkElement(); fe.DataContext = item; fe.SetBinding(CellValueProperty, binding); fe.SetValue(CellValueProperty, cellContent); BindingExpression be = fe.GetBindingExpression(CellValueProperty); be.UpdateSource(); } } }
private void updateSource(FrameworkElement fw_element) { if (fw_element is TextBox) { var expression = fw_element.GetBindingExpression(TextBox.TextProperty); if (expression != null) expression.UpdateSource(); } if (fw_element is ComboBox) { var expression = fw_element.GetBindingExpression(ComboBox.TextProperty); if (expression != null) expression.UpdateSource(); } if (fw_element is CheckBox) { var expression = fw_element.GetBindingExpression(CheckBox.IsCheckedProperty); if (expression != null) expression.UpdateSource(); } }
internal override List<BindingInfo> CreateBindings(FrameworkElement element, object dataItem, bool twoWay) { BindingInfo bindingData = new BindingInfo(); if (twoWay && this.BindingTarget != null) { bindingData.BindingExpression = element.GetBindingExpression(this.BindingTarget); if (bindingData.BindingExpression != null) { bindingData.BindingTarget = this.BindingTarget; bindingData.Element = element; return new List<BindingInfo> { bindingData }; } } foreach (DependencyProperty bindingTarget in element.GetDependencyProperties(false)) { bindingData.BindingExpression = element.GetBindingExpression(bindingTarget); if (bindingData.BindingExpression != null && bindingData.BindingExpression.ParentBinding == this.Binding) { this.BindingTarget = bindingTarget; bindingData.BindingTarget = this.BindingTarget; bindingData.Element = element; return new List<BindingInfo> { bindingData }; } } return base.CreateBindings(element, dataItem, twoWay); }
/// <summary> /// Tries to add a binding. /// </summary> /// <param name="element">The element.</param> /// <param name="property">The property.</param> /// <param name="path">The path.</param> /// <param name="mode">The mode.</param> /// <returns></returns> protected virtual bool TryAddBinding(FrameworkElement element, DependencyProperty property, string path, BindingMode mode) { if (element == null) return false; #if !SILVERLIGHT_20 if (element.GetBindingExpression(property) != null) return false; #endif var binding = new Binding(path) { Mode = mode }; element.SetBinding(property, binding); return true; }
static void PropertyChanged(FrameworkElement sender, DependencyProperty dependencyProperty) { if (sender == null) return; lock (Timers) { if (Timers.ContainsKey(sender)) { var timer = Timers[sender]; timer.Start(); } else { var delay = GetUpdateDataSourceDelay(sender); var timer = BuildTimer(sender, sender.GetBindingExpression(dependencyProperty), delay); Timers[sender] = timer; timer.Start(); } } }
private static void RefreshBindings(FrameworkElement element) { if (element == null) return; BindingExpression bindingExpression = element.GetBindingExpression(Control.FontSizeProperty); if (bindingExpression == null) return; Binding parentBinding = bindingExpression.ParentBinding; element.SetBinding(Control.FontSizeProperty, (BindingBase)parentBinding); }
private static void UpdateValidation(FrameworkElement tbox) { if(tbox == null) return; var expr = tbox.GetBindingExpression(TextBox.TextProperty); if(expr != null) expr.UpdateSource(); }