SetBinding() 공개 메소드

public SetBinding ( DependencyProperty dp, Binding binding ) : BindingExpressionBase
dp DependencyProperty
binding Binding
리턴 BindingExpressionBase
예제 #1
1
        public static void SetBindingObject(FrameworkElement obj, BindingMode mode, object source, DependencyProperty dp, string propertyName)
        {
            Type propertyType = source.GetType().GetProperty(propertyName).PropertyType;
            PropertyInfo info = source.GetType().GetProperty("RangeList");
            FANumberRangeRule rangeRule = null;
            if (info != null)
            {
                object value = info.GetValue(source, null);
                if (value != null)
                {
                    FALibrary.Utility.SerializableDictionary<string, FARange> dic =
                        (FALibrary.Utility.SerializableDictionary<string, FARange>)value;
                    if (dic.ContainsKey(propertyName))
                    {
                        rangeRule = new FANumberRangeRule(propertyType);
                        rangeRule.Range = dic[propertyName];
                        obj.Tag = rangeRule;
                        obj.Style = (Style)App.Current.Resources["TextBoxErrorStyle"];
                    }
                }
            }

            Binding bd = new Binding(propertyName);
            bd.Source = source;
            bd.Mode = mode;
            bd.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            if (rangeRule != null)
            {
                bd.NotifyOnValidationError = true;
                bd.ValidationRules.Add(rangeRule);
            }

            obj.SetBinding(dp, bd);
        }
        public override void SetBindings(DesignItem item, FrameworkElement view)
        {
            base.SetBindings(item, view);

            view.SetBinding(FrameworkElement.VerticalAlignmentProperty, new Binding("Component.VerticalOptions") { Source = item, Converter = LayoutOptionsToVerticalAlignmentConverter.Instance });
            view.SetBinding(FrameworkElement.HorizontalAlignmentProperty, new Binding("Component.HorizontalOptions") { Source = item, Converter = LayoutOptionsToHorizontalAlignmentConverter.Instance });
        }
        internal EditableFrameworkElement(CanvasEditor editor, FrameworkElement element)
        {
            Editor = editor;
            UIElement = element;
            Position = new PointNotifyPropertyChanged(new Point(
                (double)element.GetValue(Canvas.LeftProperty),
                (double)element.GetValue(Canvas.TopProperty)));
            Size = new SizeNotifyPropertyChanged(new Size(
                (double)element.GetValue(Canvas.WidthProperty),
                (double)element.GetValue(Canvas.HeightProperty)));

            Binding xBinding = new Binding(PointNotifyPropertyChanged.XProperty);
            xBinding.Source = Position;
            element.SetBinding(Canvas.LeftProperty, xBinding);

            Binding yBinding = new Binding(PointNotifyPropertyChanged.YProperty);
            yBinding.Source = Position;
            element.SetBinding(Canvas.TopProperty, yBinding);

            Binding wBinding = new Binding(SizeNotifyPropertyChanged.WidthProperty);
            wBinding.Source = Size;
            element.SetBinding(Canvas.WidthProperty, wBinding);

            Binding hBinding = new Binding(SizeNotifyPropertyChanged.HeightProperty);
            hBinding.Source = Size;
            element.SetBinding(Canvas.HeightProperty, hBinding);

            Position.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Position_PropertyChanged);
            Size.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Size_PropertyChanged);
        }
        public override void SetBindings(DesignItem item, FrameworkElement view)
        {
            base.SetBindings(item, view);

            view.SetBinding(EntryView.TextProperty, new Binding("Component.Text") { Source = item });
            view.SetBinding(EntryView.VisibilityProperty, new Binding("Component.IsVisible") { Source = item, Converter = IsVisibleToVisibilityConverter.Instance });
            view.SetBinding(EntryView.FontSizeProperty, new Binding("Component.FontSize") { Source = item });
            view.SetBinding(EntryView.ForegroundProperty, new Binding("Component.TextColor") { Source = item, Converter = ColorToBrushConverter.Instance });
        }
예제 #5
0
		protected override void SetCommonBindings(FrameworkElement marker)
		{
			base.SetCommonBindings(marker);

			marker.SetValue(ViewportPanel.YProperty, 0.0);
			marker.SetBinding(ViewportPanel.ViewportHeightProperty, DependentValueBinding);
			marker.SetBinding(ViewportPanel.ViewportWidthProperty, ColumnWidthBinding);
			marker.SetValue(ViewportPanel.ViewportVerticalAlignmentProperty, VerticalAlignment.Bottom);
			marker.SetBinding(ViewportPanel.XProperty, IndexBinding);
		}
		protected override void AddCommonBindings(FrameworkElement marker)
		{
			base.AddCommonBindings(marker);

			marker.SetValue(ViewportPanel.XProperty, 0.0);
			marker.SetBinding(ViewportPanel.ViewportWidthProperty, viewportWidthBinding);
			marker.SetValue(ViewportPanel.ViewportHeightProperty, 0.85);
			marker.SetValue(ViewportPanel.ViewportHorizontalAlignmentProperty, HorizontalAlignment.Left);
			marker.SetBinding(ViewportPanel.YProperty, viewportYBinding);
		}
 public static void SetBindingObject(FrameworkElement obj, BindingMode mode, object source, DependencyProperty dp, string propertyName)
 {
     Binding bd = new Binding(propertyName);
     bd.Source = source;
     bd.Mode = mode;
     obj.SetBinding(dp, bd);
 }
        /// <summary>
        /// Replaces the content for a <see cref="DataField"/> with another control and updates the bindings.
        /// </summary>
        /// <param name="field">The <see cref="DataField"/> whose <see cref="TextBox"/> will be replaced.</param>
        /// <param name="newControl">The new control you're going to set as <see cref="DataField.Content" />.</param>
        /// <param name="dataBindingProperty">The control's property that will be used for data binding.</param>        
        /// <param name="bindingSetupFunction">
        ///  An optional <see cref="Action"/> you can use to change parameters on the newly generated binding before
        ///  it is applied to <paramref name="newControl"/>
        /// </param>
        /// <param name="sourceProperty">The source dependency property to use for the binding.</param>
        public static void ReplaceContent(this DataField field, FrameworkElement newControl, DependencyProperty dataBindingProperty, Action<Binding> bindingSetupFunction, DependencyProperty sourceProperty)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            if (newControl == null)
            {
                throw new ArgumentNullException("newControl");
            }

            // Construct new binding by copying existing one, and sending it to bindingSetupFunction
            // for any changes the caller wants to perform
            Binding newBinding = field.Content.GetBindingExpression(sourceProperty).ParentBinding.CreateCopy();

            if (bindingSetupFunction != null)
            {
                bindingSetupFunction(newBinding);
            }

            // Replace field
            newControl.SetBinding(dataBindingProperty, newBinding);
            field.Content = newControl;
        }
예제 #9
0
 public static void BindProperty(FrameworkElement element, object source, 
     string path, DependencyProperty property, BindingMode mode)
 {
     var binding = new Binding(path);
     binding.Source = source;
     binding.Mode = mode;
     element.SetBinding(property, binding);
 }
 public static void Bind(object dataSource, string sourcePath, FrameworkElement destinationObject, DependencyProperty dp)
 {
     Binding binding = new Binding();
     binding.Source = dataSource;
     binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
     binding.Path = new PropertyPath(sourcePath);
     destinationObject.SetBinding(dp, binding);
 }
예제 #11
0
 public static void RegisterForNotification(string property, FrameworkElement frameworkElement, PropertyChangedCallback OnCallBack)
 {
     Binding binding2 = new Binding(property);
     binding2.set_Source(frameworkElement);
     Binding binding = binding2;
     DependencyProperty property2 = DependencyProperty.RegisterAttached("ListenAttached" + property, typeof(object), typeof(UserControl), new PropertyMetadata(OnCallBack));
     frameworkElement.SetBinding(property2, binding);
 }
예제 #12
0
 public static Oscillator AmplitudeModulate(this Oscillator oscillator, FrameworkElement target, DependencyProperty property)
 {
     Binding frequencyBinding = new Binding();
     frequencyBinding.Mode = BindingMode.TwoWay;
     frequencyBinding.Source = oscillator.AmplitudeModulator;
     frequencyBinding.Path = new PropertyPath("ModulationFrequency");
     target.SetBinding(property, frequencyBinding);
     return oscillator;
 }
예제 #13
0
		protected override void AddCommonBindings(FrameworkElement marker)
		{
			base.AddCommonBindings(marker);

			marker.SetValue(ViewportPanel.YProperty, 0.0);

			if (!String.IsNullOrEmpty(DependentValuePath))
			{
				viewportHeightBinding = new Binding(DependentValuePath);
			}

			marker.SetBinding(ViewportPanel.ViewportHeightProperty, viewportHeightBinding);

			if (ViewportPanel.GetViewportWidth(marker).IsNaN())
				marker.SetValue(ViewportPanel.ViewportWidthProperty, 0.85);
			marker.SetValue(ViewportPanel.ViewportVerticalAlignmentProperty, VerticalAlignment.Bottom);
			marker.SetBinding(ViewportPanel.XProperty, viewportXBinding);
		}
예제 #14
0
 public static Attenuator Attenuate(this Mixer mixer, FrameworkElement target, DependencyProperty property)
 {
     Attenuator attenuator = new Attenuator() { Input = mixer };
     Binding binding = new Binding();
     binding.Mode = BindingMode.TwoWay;
     binding.Source = attenuator;
     binding.Path = new PropertyPath("Attenuation");
     target.SetBinding(property, binding);
     return attenuator;
 }
        public static void BindProperty(FrameworkElement element, BindableProperty property)
        {
            Guard.ArgumentNotNull(element, "element");

            var enabledBinding = new Binding("ReadOnly");
            enabledBinding.Converter = new BooleanInverseConverter();
            enabledBinding.Source = property;
            element.SetBinding(UIElement.IsEnabledProperty, enabledBinding);

        }
 private void BindControlToViewModel(ViewModel viewModel, string viewModelProperty, FrameworkElement control, DependencyProperty controlProperty)
 {
     var binding = new Binding
     {
         Source = viewModel,
         Path = new PropertyPath(viewModelProperty),
         Mode = BindingMode.TwoWay,
         UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
     };
     control.SetBinding(controlProperty, binding);
 }
예제 #17
0
        /// <summary>
        ///     Replaces a <see cref="DataField" />'s <see cref="TextBox" /> control with another control,
        ///     taking care of automatically updating the bindings and overriding the existing converter
        ///     with another one
        /// </summary>
        /// <param name="newControl">The new control you're going to set as <see cref="DataField.Content" /></param>
        /// <param name="dataBindingProperty">The control's property that will be used for data binding</param>        
        /// <param name="bindingSetupFunction">
        ///     A function you can use to change parameters on the newly generated binding before
        ///     it is applied to <paramref name="newControl"/>
        /// </param>
        public static void ReplaceTextBox(this DataField field, FrameworkElement newControl, DependencyProperty dataBindingProperty, Action<Binding> bindingSetupFunction)
        {
            // Construct new binding by copying existing one, and sending it to bindingSetupFunction
            // for any changes the caller wants to perform
            Binding newBinding = field.Content.GetBindingExpression(TextBox.TextProperty).ParentBinding.CreateCopy();
            bindingSetupFunction(newBinding);

            // Replace field
            newControl.SetBinding(dataBindingProperty, newBinding);
            field.Content = newControl;
        }
예제 #18
0
 public GameObjectShape(MyShape model)
 {
     this.Model = model;
     if(model is PlayerModel || model is EnemyModel || model is PowerUPModel)
     {
         this.shap = new Rectangle();
         (shap as Shape).Fill = model.B;
         shap.DataContext = model;
         shap.SetBinding(Rectangle.WidthProperty, new Binding("Area.Width"));
         shap.SetBinding(Rectangle.HeightProperty, new Binding("Area.Height"));
     }
     else if(model is EnemyBulletModel || model is PlayerBulletModel)
     {
         this.shap = new Ellipse();
         (shap as Shape).Fill = model.B;
         shap.DataContext = model;
         shap.SetBinding(Ellipse.WidthProperty, new Binding("Area.Width"));
         shap.SetBinding(Ellipse.HeightProperty, new Binding("Area.Height"));
     }
 }
예제 #19
0
 public static Attenuator Attenuate(this Panner panner, FrameworkElement target, DependencyProperty property)
 {
     Attenuator attenuator = new Attenuator() { Input = panner, Attenuation = (double)target.GetValue(property) };
     Binding binding = new Binding();
     binding.Mode = BindingMode.TwoWay;
     binding.Source = attenuator;
     binding.Path = new PropertyPath("Attenuation");
     target.SetBinding(property, binding);
     panner.Output = attenuator;
     return attenuator;
 }
        // Listen for change of the dependency property
        public void RegisterForNotification(string propertyName, FrameworkElement element, PropertyChangedCallback callback)
        {
            // bind to dependency property
            var b = new Binding(propertyName) { Source = element };
            var prop = DependencyProperty.RegisterAttached(
                "NotifyAttached" + propertyName,
                typeof(object),
                typeof(UserControl),
                new PropertyMetadata(callback));

            element.SetBinding(prop, b);
        }
예제 #21
0
        private void OnContentChanged(FrameworkElement oldValue, FrameworkElement newValue) {
            if (oldValue != null) {
                BindingOperations.ClearBinding(oldValue, DataContextProperty);
            }

            if (newValue != null && newValue.DataContext == null) {
                newValue.SetBinding(DataContextProperty, new Binding {
                    Path = new PropertyPath(nameof(DataContext)),
                    Source = this
                });
            }
        }
		private void OnTemplateChanged()
		{
			BindingOperations.ClearAllBindings(rectangleControl);
			renderPanel.Children.Remove(rectangleControl);

			var template = RectangleTemplate;
			if (template != null)
			{
				rectangleControl = (FrameworkElement)template.LoadContent();
				rectangleControl.SetBinding(ViewportPanel.ViewportBoundsProperty, new Binding("SelectedRectangle") { Source = this });
				renderPanel.Children.Add(rectangleControl);
			}
		}
        public static void SetTitleBinding(object documentContentView, DependencyProperty property, FrameworkElement target, bool convertToString = false) {
            IDocumentViewModel documentViewModel = ViewHelper.GetViewModelFromView(documentContentView) as IDocumentViewModel;
            if(documentViewModel == null) return;
            if(ExpressionHelper.PropertyHasImplicitImplementation(documentViewModel, i => i.Title)) {
                Binding binding = new Binding("Title") { Source = documentViewModel };
#if !SILVERLIGHT
                if(convertToString)
                    binding.Converter = new ObjectToStringConverter();
#endif
                target.SetBinding(property, binding);
            } else {
                new TitleUpdater(convertToString, documentViewModel, target, property).Update(target, documentViewModel);
            }
        }
예제 #24
0
        public static void AddBinding(FrameworkElement element, DependencyProperty property, string bindingPath)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }
            else if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            Binding binding = new Binding(bindingPath);

            element.SetBinding(property, binding);
        }
예제 #25
0
        public void Attach(FrameworkElement target, Binding binding)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            Detach();
            targetElement = target;
            targetElement.SetBinding(dependencyProperty, binding);
        }
        public override void SetBindings(DesignItem item, FrameworkElement view)
        {
            base.SetBindings(item, view);

            view.SetBinding(LabelView.ContentProperty, new Binding("ContentProperty.ValueOnInstanceOrView") { Source = item });
            view.SetBinding(LabelView.VisibilityProperty, new Binding("Component.IsVisible") { Source = item, Converter = IsVisibleToVisibilityConverter.Instance });
            view.SetBinding(LabelView.HorizontalContentAlignmentProperty, new Binding("Component.XAlign") { Source = item, Converter = XAlignToHorizontalAlignmentConverter.Instance });
            view.SetBinding(LabelView.VerticalContentAlignmentProperty, new Binding("Component.YAlign") { Source = item, Converter = YAlignToVerticalAlignmentConverter.Instance });
            view.SetBinding(LabelView.FontSizeProperty, new Binding("Component.FontSize") { Source = item });
            view.SetBinding(LabelView.ForegroundProperty, new Binding("Component.TextColor") { Source = item, Converter = ColorToBrushConverter.Instance });
        }
예제 #27
0
        public BindingShim(FrameworkElement element, Binding binding, Action changedHandler)
        {
            _element = element;
            _binding = binding;

            _instanceCount++;
            _attachedDP = DependencyProperty.RegisterAttached("BoundParameter" + _instanceCount,
                                                              typeof(object), typeof(BindingShim),
                                                              new PropertyMetadata(OnChanged));

            _element.SetBinding(_attachedDP, _binding);
            _value = _element.GetValue(_attachedDP);

            // Initialize _changedHandler after setting up the binding so we don't invoke
            // it when the OnChanged handled gets called as a side-effect of setting the binding!
            _changedHandler = changedHandler;
        }
예제 #28
0
    /// <summary>
    /// Generates the editing element.
    /// </summary>
    /// <param name="cell">Cell for content</param>
    /// <param name="dataItem">Data item for binding</param>
    protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
    {
      StackPanel panel = new StackPanel();
      panel.Orientation = Orientation.Horizontal;

      if (dataItem != null && Binding != null)
      {
        _editControl = CreateEditingElement();
        _editControl.SetBinding(EditingElementProperty, Binding);
        panel.Children.Add(_editControl);

        PropertyStatus status = new PropertyStatus();
        status.SetBinding(PropertyStatus.PropertyProperty, Binding);

        panel.Children.Add(status);
      }

      return panel;
    }
		private void SetBindings(FrameworkElement marker)
		{
			ViewportPanel panel = marker as ViewportPanel;
			marker.SetBinding(ViewportPanel.ViewportBoundsProperty, boundsBinding);

			Ellipse crownEllipse = (Ellipse)panel.FindName("crownEllipse");
			crownEllipse.SetBinding(ViewportPanel.ViewportWidthProperty, crownWidthBinding);
			crownEllipse.SetBinding(ViewportPanel.ViewportHeightProperty, crownHeightBinding);
			crownEllipse.SetBinding(ViewportPanel.YProperty, crownYBinding);
			crownEllipse.SetBinding(ViewportPanel.XProperty, xBinding);
			crownEllipse.SetBinding(Ellipse.FillProperty, fillBinding);
			crownEllipse.SetBinding(Ellipse.StrokeProperty, strokeBinding);

			Rectangle trunkRect = (Rectangle)panel.FindName("trunkRect");

			trunkRect.SetBinding(ViewportPanel.XProperty, xBinding);
			trunkRect.SetBinding(ViewportPanel.ViewportWidthProperty, trunkWidthBinding);
			trunkRect.SetBinding(ViewportPanel.ViewportHeightProperty, trunkHeightBinding);
			trunkRect.SetBinding(Rectangle.FillProperty, fillBinding);
		}
예제 #30
0
 public static void BindEditor(FrameworkElement editor, DependencyProperty dp, PropertyAttribute pa, IValueConverter converter)
 {
     Binding editorBinding = null;
     if (pa.PropertyBinding != null)
     {
         editorBinding = pa.PropertyBinding;
         if (pa.PropertyBinding.Source == null)
         {
             editor.DataContext = pa.SelectedObject;
         }
     }
     else
     {
         editorBinding = new Binding(pa.MemberName);
         editorBinding.Mode = IsReadOnlySource(pa) ? BindingMode.OneWay : BindingMode.TwoWay;
         editorBinding.NotifyOnValidationError = true;
         editorBinding.ValidatesOnExceptions = true;
         editorBinding.ValidatesOnDataErrors = true;
         editorBinding.Converter = converter;
         editorBinding.Source = pa.SelectedObject;
     }
     editor.SetBinding(dp, editorBinding);
 }