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


C# FrameworkElement.SetBinding方法代码示例

本文整理汇总了C#中FrameworkElement.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.SetBinding方法的具体用法?C# FrameworkElement.SetBinding怎么用?C# FrameworkElement.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FrameworkElement的用法示例。


在下文中一共展示了FrameworkElement.SetBinding方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Register

		public static void Register(FrameworkElement obj, DependencyProperty property, Action<object, object> changed)
		{
			if (helpers == null)
				helpers = new List<Helper>();

			var helper = new Helper(obj, property, changed, obj.GetValue(property));
			var binding = new Binding();
			binding.Path = new PropertyPath("Property");
			binding.Source = helper;
			binding.Mode = BindingMode.TwoWay;
			obj.SetBinding(property, binding);
			
			helpers.Add(helper);
		}
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:14,代码来源:DependencyPropertyChangedEvent.cs

示例2: Register

        /// <summary>Registers an event callback on a given dependency property. </summary>
        /// <param name="frameworkElement">The source framework element. </param>
        /// <param name="property">The property to register the callback for. </param>
        /// <param name="handler">The event handler. </param>
        public static void Register(FrameworkElement frameworkElement, DependencyProperty property, Action<object, object> handler)
        {
            if (_dependencyPropertyRegistrations == null)
                _dependencyPropertyRegistrations = new List<DependencyPropertyRegistration>();

            var helper = new DependencyPropertyRegistration(
                frameworkElement, property, handler, frameworkElement.GetValue(property));
            
            var binding = new Binding();
            binding.Path = new PropertyPath("Property");
            binding.Source = helper;
            binding.Mode = BindingMode.TwoWay;
            
            frameworkElement.SetBinding(property, binding);
            
            _dependencyPropertyRegistrations.Add(helper);
        }
开发者ID:RareNCool,项目名称:MyToolkit,代码行数:21,代码来源:DependencyPropertyChangedEvent.cs

示例3: UpdateBindingsOnElement

        /// <summary>
        /// Finds any bindings on an element and updates the ones in which Mode is TwoWay
        /// to set the two Boolean properties to true.
        /// </summary>
        /// <param name="element">The element.</param>
        private void UpdateBindingsOnElement(FrameworkElement element)
        {
            if (this.DataContext == null)
            {
                return;
            }

            // DataFields will run themselves, so don't bother if we're looking at a DataField.
            if (!(element is DataField))
            {
                List<DependencyProperty> dependencyProperties = ValidationUtil.GetDependencyPropertiesForElement(element);
                Debug.Assert(dependencyProperties != null, "GetDependencyPropertiesForElement() should never return null.");

                foreach (DependencyProperty dependencyProperty in dependencyProperties)
                {
                    if (dependencyProperty != null)
                    {
                        BindingExpression bindingExpression = element.GetBindingExpression(dependencyProperty);

                        if (bindingExpression != null && bindingExpression.ParentBinding != null)
                        {
                            Binding binding = ValidationUtil.CopyBinding(bindingExpression.ParentBinding);

                            if (binding.Path != null && !String.IsNullOrEmpty(binding.Path.Path) && binding.Mode == BindingMode.TwoWay)
                            {
                                PropertyInfo propertyInfo = this.DataContext.GetType().GetPropertyInfo(binding.Path.Path);

                                if (propertyInfo == null || !propertyInfo.CanWrite)
                                {
                                    // Ignore bindings to nonexistent or read-only properties.
                                    continue;
                                }

                                binding.ValidatesOnExceptions = true;
                                binding.NotifyOnValidationError = true;
                            }

                            if (binding.Converter == null)
                            {
                                binding.Converter = new DataFormValueConverter();
                            }

                            element.SetBinding(dependencyProperty, binding);

                            TextBox textBox = element as TextBox;

                            if (textBox != null)
                            {
                                if (binding.UpdateSourceTrigger != UpdateSourceTrigger.Explicit)
                                {
                                    this._lostFocusFired[textBox] = true;

                                    textBox.LostFocus -= new RoutedEventHandler(this.OnTextBoxLostFocus);
                                    textBox.LostFocus += new RoutedEventHandler(this.OnTextBoxLostFocus);
                                    textBox.TextChanged -= new TextChangedEventHandler(this.OnTextBoxTextChanged);
                                    textBox.TextChanged += new TextChangedEventHandler(this.OnTextBoxTextChanged);
                                }
                                else
                                {
                                    if (this._lostFocusFired.ContainsKey(textBox))
                                    {
                                        this._lostFocusFired.Remove(textBox);
                                    }

                                    textBox.LostFocus -= new RoutedEventHandler(this.OnTextBoxLostFocus);
                                    textBox.TextChanged -= new TextChangedEventHandler(this.OnTextBoxTextChanged);
                                }
                            }
                        }
                    }
                }

                int childrenCount = VisualTreeHelper.GetChildrenCount(element);

                for (int i = 0; i < childrenCount; i++)
                {
                    FrameworkElement childElement = VisualTreeHelper.GetChild(element, i) as FrameworkElement;

                    // Stop if we've found a child DataForm.
                    if (childElement != null && childElement.GetType() != typeof(DataForm))
                    {
                        this.UpdateBindingsOnElement(childElement);
                    }
                }
            }
        }
开发者ID:modulexcite,项目名称:SilverlightToolkit,代码行数:91,代码来源:DataField.cs

示例4: CreateTwoWayBinding

 /// <summary>
 /// Create two way property binding.
 /// </summary>
 private void CreateTwoWayBinding(FrameworkElement fe, DependencyProperty dp, string propertyPath)
 {
     Binding binding = new Binding(propertyPath);
     binding.Mode = BindingMode.TwoWay;
     binding.Source = this;
     fe.SetBinding(dp, binding);
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:10,代码来源:FlowDocumentScrollViewer.cs

示例5: ApplyBinding

		public static void ApplyBinding(FrameworkElement source, FrameworkElement target, string propertyPath, DependencyProperty property, IValueConverter converter = null, object converterParameter = null)
		{
			if (source == null || target == null)
				return;

#if WINDOWS_STORE || WINDOWS_PHONE_APP
            var binding = new Windows.UI.Xaml.Data.Binding();
#elif WINDOWS_PHONE
			var binding = new System.Windows.Data.Binding();
#endif

			binding.Source = source;
			binding.Path = new PropertyPath(propertyPath);

			binding.Converter = converter;
			binding.ConverterParameter = converterParameter;

			target.SetBinding(property, binding);
		}
开发者ID:selaromdotnet,项目名称:Coding4FunToolkit,代码行数:19,代码来源:ButtonBaseHelper.cs

示例6: ApplyBinding

            /// <summary>
            /// Applies the Binding represented by the SetterValueBindingHelper.
            /// </summary>
            /// <param name="element">Element to apply the Binding to.</param>
            /// <param name="item">SetterValueBindingHelper representing the Binding.</param>
            private static void ApplyBinding(FrameworkElement element, SetterValueBindingHelper item)
            {
                if ((null == item.Property) || (null == item.Binding))
                {
                    throw new ArgumentException(
                        "SetterValueBindingHelper's Property and Binding must both be set to non-null values.");
                }

                // Get the type on which to set the Binding
                TypeInfo typeInfo = null;
                if (null == item.Type)
                {
                    // No type specified; setting for the specified element
                    typeInfo = element.GetType().GetTypeInfo();
                }
                else
                {
                    // Try to get the type from the type system
                    var type = System.Type.GetType(item.Type);
                    if (type != null)
                    {
                        typeInfo = type.GetTypeInfo();
                    }

                    if (type == null)
                    {

                        // Search for the type in the list of assemblies
                        foreach (var assembly in AssembliesToSearch)
                        {
                            // Match on short or full name
                            typeInfo = assembly.DefinedTypes.FirstOrDefault(t => (t.FullName == item.Type) || (t.Name == item.Type));
                            if (null != typeInfo)
                            {
                                // Found; done searching
                                break;
                            }
                        }
                        if (null == typeInfo)
                        {
                            // Unable to find the requested type anywhere
                            throw new ArgumentException(
                                string.Format(
                                    CultureInfo.CurrentCulture,
                                    "Unable to access type \"{0}\". Try using an assembly qualified type name.",
                                    item.Type));
                        }
                    }
                }

                // Get the DependencyProperty for which to set the Binding
                DependencyProperty property = null;

                var field = GetDPField(item.Property, typeInfo);

                if (null != field)
                {
                    property = field.GetValue(null) as DependencyProperty;
                }
                if (null == property)
                {
                    // Unable to find the requsted property
                    throw new ArgumentException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            "Unable to access DependencyProperty \"{0}\" on type \"{1}\".",
                            item.Property,
                            typeInfo.Name));
                }

                // Set the specified Binding on the specified property
                element.SetBinding(property, item.Binding);
            }
开发者ID:modulexcite,项目名称:WizardControl-UWP,代码行数:78,代码来源:SetterValueBindingHelper.cs


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