当前位置: 首页>>代码示例>>C#>>正文


C# FrameworkElement.GetBindingExpression方法代码示例

本文整理汇总了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.");
        }
开发者ID:mogliang,项目名称:Generic-WPF-Form-Controls,代码行数:33,代码来源:CustomValidation.cs

示例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();
         }
     }
 }
开发者ID:valeriob,项目名称:Routing,代码行数:12,代码来源:UpdateDataSourceDelayed.cs

示例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 () );
     }
 }
开发者ID:divyang4481,项目名称:REM,代码行数:21,代码来源:ConfigurationBehaviorExtensions.cs

示例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();
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:18,代码来源:ValueEditorUtils.cs

示例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;
        }
开发者ID:gertjvr,项目名称:ModernWPF,代码行数:41,代码来源:LabelValidationHelper.cs

示例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();
                }
            }
        }
开发者ID:modulexcite,项目名称:SoftFluent.Windows,代码行数:16,代码来源:PropertyGrid.xaml.cs

示例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();
                }
            }
        }
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:32,代码来源:DataGridColumn.cs

示例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();
     }
 }
开发者ID:GrayJumba,项目名称:Onion,代码行数:18,代码来源:Subject.xaml.cs

示例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);
 }
开发者ID:expanz,项目名称:expanz-Microsoft-XAML-SDKs,代码行数:27,代码来源:DataGridBoundColumn.cs

示例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;
        }
开发者ID:Mrding,项目名称:Ribbon,代码行数:23,代码来源:DefaultBinder.cs

示例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();
                }
            }
        }
开发者ID:valeriob,项目名称:Routing,代码行数:21,代码来源:UpdateDataSourceDelayed.cs

示例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);
 }
开发者ID:sulerzh,项目名称:chart,代码行数:10,代码来源:XYLabelsPanel.cs

示例13: UpdateValidation

 private static void UpdateValidation(FrameworkElement tbox)
 {
     if(tbox == null)
         return;
     var expr = tbox.GetBindingExpression(TextBox.TextProperty);
     if(expr != null)
         expr.UpdateSource();
 }
开发者ID:Swizzy,项目名称:xeBuildGUI,代码行数:8,代码来源:MainWindow.xaml.cs


注:本文中的System.Windows.FrameworkElement.GetBindingExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。