當前位置: 首頁>>代碼示例>>C#>>正文


C# FrameworkElement.SetBinding方法代碼示例

本文整理匯總了C#中Windows.UI.Xaml.FrameworkElement.SetBinding方法的典型用法代碼示例。如果您正苦於以下問題:C# FrameworkElement.SetBinding方法的具體用法?C# FrameworkElement.SetBinding怎麽用?C# FrameworkElement.SetBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.UI.Xaml.FrameworkElement的用法示例。


在下文中一共展示了FrameworkElement.SetBinding方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SetBinding

 /// <summary>
 /// Sets a binding from code
 /// </summary>
 /// <param name="element"></param>
 /// <param name="property"></param>
 /// <param name="source"></param>
 /// <param name="path"></param>
 /// <param name="converter"></param>
 public static void SetBinding(FrameworkElement element, DependencyProperty property, object source, string path, IValueConverter converter = null)
 {
     Binding binding = new Binding();
     binding.Source = source;
     binding.Path = new PropertyPath(path);
     binding.Converter = converter;
     element.SetBinding(property, binding);
 }
開發者ID:knowlatest,項目名稱:Windows8StartKit,代碼行數:16,代碼來源:BindingHelper.cs

示例2: BindProperty

 public static void BindProperty(FrameworkElement element, object source,
     string path, DependencyProperty property, BindingMode mode)
 {
     var binding = new Binding();
     binding.Path = new PropertyPath(path);
     binding.Source = source;
     binding.Mode = mode;
     element.SetBinding(property, binding);
 }
開發者ID:kondoumh,項目名稱:MetroCsStudyDraw,代碼行數:9,代碼來源:BindingHelper.cs

示例3: BindToControl

        //public static void BindToControl(this LightweightViewModelBase vm, FrameworkElement control, DependencyProperty propertyTo, string propertyFrom, bool twoWay = false, IValueConverter converter = null, object converterParam = null)
        //{
        //    control.SetBinding(propertyTo, new Binding() { Source = vm, Path = new PropertyPath(propertyFrom), Converter = converter, ConverterParameter = converterParam, Mode = twoWay ? BindingMode.TwoWay : BindingMode.OneWay });
        //}

        public static void BindToControl(this BaseViewModel vm, FrameworkElement control, DependencyProperty propertyTo, string propertyFrom, bool twoWay = false, IValueConverter converter = null, object converterParam = null)
        {
            control.SetBinding(propertyTo, new Binding() { Source = vm, Path = new PropertyPath(propertyFrom), Converter = converter, ConverterParameter = converterParam, Mode = twoWay ? BindingMode.TwoWay : BindingMode.OneWay });
        }
開發者ID:AlexKven,項目名稱:OneAppAway-RTM,代碼行數:9,代碼來源:HelperFunctions.cs

示例4: CreateBinding

 protected void CreateBinding(
     DependencyProperty sourceDependencyProperty,
     string sourceDependencyPropertyName,
     FrameworkElement targetElement,
     DependencyProperty targetElementDependencyProperty)
 {
     var binding = ReadLocalValue(sourceDependencyProperty) as BindingExpression;
     if (binding != null)
         targetElement.SetBinding(targetElementDependencyProperty, binding.ParentBinding);
     else
     {
         targetElement.SetBinding(targetElementDependencyProperty, new Binding
         {
             Path = new PropertyPath(sourceDependencyPropertyName),
             Source = this
         });
     }
 }
開發者ID:RareNCool,項目名稱:MyToolkit,代碼行數:18,代碼來源:DataGridColumnBase.cs

示例5: SetAppBarForegroundBinding

		void SetAppBarForegroundBinding(FrameworkElement element)
		{
			element.SetBinding(Windows.UI.Xaml.Controls.Control.ForegroundProperty,
				new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("Control.ToolbarForeground"), Source = this, RelativeSource = new RelativeSource { Mode = RelativeSourceMode.TemplatedParent } });
		}
開發者ID:ytn3rd,項目名稱:Xamarin.Forms,代碼行數:5,代碼來源:MasterDetailPageRenderer.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
            Type type = null;
            TypeInfo typeInfo = null;
            if (null == item.Type)
            {
                // No type specified; setting for the specified element
                type = element.GetType();
                typeInfo = type.GetTypeInfo();
            }
            else
            {
                // Try to get the type from the type system
                type = System.Type.GetType(item.Type);
                if (null == type)
                {
                    // Search for the type in the list of assemblies
                    foreach (var assembly in AssembliesToSearch)
                    {
                        // Match on short or full name
                        typeInfo = assembly.DefinedTypes
                            .Where(t => (t.FullName == item.Type) || (t.Name == item.Type))
                            .FirstOrDefault();
                        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));
                    }
                }
                else
                {
                    typeInfo = type.GetTypeInfo();
                }
            }

            // Get the DependencyProperty for which to set the Binding
            DependencyProperty property = null;
            var field = typeInfo.GetDeclaredProperty(item.Property + "Property"); // type.GetRuntimeField(item.Property + "Property");
            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, type.Name));
            }

            // Set the specified Binding on the specified property
            element.SetBinding(property, item.Binding);
        }
開發者ID:rmarinho,項目名稱:babysmash,代碼行數:73,代碼來源:SetterValueBindingHelper.cs

示例7: SetBinding

 private void SetBinding(FrameworkElement obj, DependencyProperty p, string path)
 {
     Binding b = new Binding();
     b.Source = this;
     b.Path = new PropertyPath(path);
     b.Mode = BindingMode.OneWay;
     obj.SetBinding(p, b);
 }
開發者ID:jasine,項目名稱:weather,代碼行數:8,代碼來源:ShowImage.xaml.cs

示例8: SetBinding

 private void SetBinding(DependencyProperty dp, FrameworkElement element)
 {
     var binding = new Binding
     {
         Source = this,
         Path = new PropertyPath("Value"),
         Mode = BindingMode.TwoWay
     };
     element.SetBinding(dp, binding);
 }
開發者ID:ridomin,項目名稱:waslibs,代碼行數:10,代碼來源:PropertySet.cs

示例9: WidthChanged

 private static void WidthChanged(FrameworkElement element, IPropertyChangedArgs<string> args)
 {
     element.SetBinding(FrameworkElement.WidthProperty, args.NewValue);
 }
開發者ID:jamesqo,項目名稱:Sirloin,代碼行數:4,代碼來源:BindingPaths.cs

示例10: SetAppBarForegroundBinding

		void SetAppBarForegroundBinding(FrameworkElement element)
		{
			element.SetBinding(Control.ForegroundProperty,
				new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("TitleBrush"), Source = _container, RelativeSource = new RelativeSource { Mode = RelativeSourceMode.TemplatedParent } });
		}
開發者ID:Costo,項目名稱:Xamarin.Forms,代碼行數:5,代碼來源:NavigationPageRenderer.cs

示例11: WaitForDataContext

        public Task WaitForDataContext(FrameworkElement obj)
        {
            if(obj.DataContext != null)
            {
                this.Complete(obj.DataContext);
            }
            else
            {
                var b = new Binding();
                var prop = DependencyProperty.RegisterAttached(
                    "ListenAttachedDataContext" + binder.GetHashCode().ToString("{0:x}") + this.GetHashCode().ToString("{0:x}"),
                    typeof(object),
                    typeof(DataContextChangedDetector),
                    new PropertyMetadata(null, new PropertyChangedCallback(onPropertyChanged)));

                obj.SetBinding(prop, b);
            }
            return tcs.Task;
        }
開發者ID:AmrReda,項目名稱:Windows.UI.Interactivity,代碼行數:19,代碼來源:InteractivityBase.cs


注:本文中的Windows.UI.Xaml.FrameworkElement.SetBinding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。