本文整理汇总了C#中System.Windows.FrameworkElement.GetBindingExpression方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.GetBindingExpression方法的具体用法?C# FrameworkElement.GetBindingExpression怎么用?C# FrameworkElement.GetBindingExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.GetBindingExpression方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ForceValidation
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.");
}
示例2: ForceDataBind
static void ForceDataBind(FrameworkElement sender, DependencyProperty dependencyProperty)
{
lock (Timers)
{
if( Timers.ContainsKey(sender))
{
var timer = Timers[sender];
timer.Stop();
sender.GetBindingExpression(dependencyProperty).UpdateSource();
}
}
}
示例3: OverideConfigurationBehavior
/// <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 () );
}
}
示例4: UpdateBinding
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();
}
}
}
示例5: ParseMetadata
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;
}
示例6: FocusChildUsingBinding
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();
}
}
}
示例7: OnPastingCellClipboardContent
/// 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();
}
}
}
示例8: 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();
}
}
示例9: CreateBindings
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);
}
示例10: TryAddBinding
/// <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;
}
示例11: PropertyChanged
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();
}
}
}
示例12: RefreshBindings
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);
}
示例13: UpdateValidation
private static void UpdateValidation(FrameworkElement tbox)
{
if(tbox == null)
return;
var expr = tbox.GetBindingExpression(TextBox.TextProperty);
if(expr != null)
expr.UpdateSource();
}