Beispiel #1
0
        /// <summary>
        /// Binds to the specified child <paramref name="binding"/> of this binding.
        /// </summary>
        /// <remarks>
        /// This can be used to bind to child objects of your view model, for example
        /// <code>model.SomeProperty.ChildProperty</code>.
        /// </remarks>
        /// <example>
        /// Use this like so:
        /// <code>
        ///     public class MyChild { public SomeChildProperty { get; set; } }
        ///     public class MyModel { public ChildObject { get; set; } }
        ///
        ///     var model = new MyModel();
        ///     Binding.Property(model, (MyModel m) => m.ChildObject).Child(Binding.Property("SomeChildProperty"));
        /// </code>
        /// </example>
        /// <returns>The binding to the child property accessed through the current binding.</returns>
        /// <param name="binding">Binding to get the child value from this binding.</param>
        /// <typeparam name="TValue">The type of the child property value.</typeparam>
        public DirectBinding <TValue> Child <TValue>(IndirectBinding <TValue> binding)
        {
            object childBindingReference          = null;
            EventHandler <EventArgs> eventHandler = null;
            EventHandler <EventArgs> valueChanged = (sender, e) =>
            {
                binding.RemoveValueChangedHandler(childBindingReference, eventHandler);
                eventHandler?.Invoke(sender, e);
                childBindingReference = binding.AddValueChangedHandler(DataValue, eventHandler);
            };

            return(new DelegateBinding <TValue>(
                       () => binding.GetValue(DataValue),
                       v => binding.SetValue(DataValue, v),
                       addChangeEvent: ev =>
            {
                eventHandler = ev;
                DataValueChanged += valueChanged;
                childBindingReference = binding.AddValueChangedHandler(DataValue, ev);
            },
                       removeChangeEvent: ev =>
            {
                binding.RemoveValueChangedHandler(childBindingReference, ev);
                DataValueChanged -= valueChanged;
            }
                       ));
        }
Beispiel #2
0
        /// <summary>
        /// Binds to the specified child <paramref name="binding"/> of this binding.
        /// </summary>
        /// <remarks>
        /// This can be used to bind to child objects of your view model, for example
        /// <code>model.SomeProperty.ChildProperty</code>.
        /// </remarks>
        /// <example>
        /// Use this like so:
        /// <code>
        ///     public class MyChild { public SomeChildProperty { get; set; } }
        ///     public class MyModel { public ChildObject { get; set; } }
        ///
        ///     var model = new MyModel();
        ///     Binding.Property(model, (MyModel m) => m.ChildObject).Child(Binding.Property("SomeChildProperty"));
        /// </code>
        /// </example>
        /// <returns>The binding to the child property accessed through the current binding.</returns>
        /// <param name="binding">Binding to get the child value from this binding.</param>
        /// <typeparam name="TNewValue">The type of the child property value.</typeparam>
        public new BindableBinding <T, TNewValue> Child <TNewValue>(IndirectBinding <TNewValue> binding)
        {
            object childBindingReference          = null;
            EventHandler <EventArgs> eventHandler = null;
            EventHandler <EventArgs> valueChanged = (sender, e) =>
            {
                binding.RemoveValueChangedHandler(childBindingReference, eventHandler);
                eventHandler?.Invoke(sender, e);
                childBindingReference = binding.AddValueChangedHandler(DataValue, eventHandler);
            };

            return(new BindableBinding <T, TNewValue>(
                       DataItem,
                       c => binding.GetValue(DataValue),
                       (c, v) => binding.SetValue(DataValue, v),
                       addChangeEvent: (c, ev) =>
            {
                eventHandler = ev;
                DataValueChanged += valueChanged;
                childBindingReference = binding.AddValueChangedHandler(DataValue, ev);
            },
                       removeChangeEvent: (c, ev) =>
            {
                binding.RemoveValueChangedHandler(childBindingReference, ev);
                DataValueChanged -= valueChanged;
            }
                       ));
        }
Beispiel #3
0
        /// <summary>
        /// Binds to the specified child <paramref name="binding"/> of this binding.
        /// </summary>
        /// <remarks>
        /// This can be used to bind to child objects of your view model, for example
        /// <code>model.SomeProperty.ChildProperty</code>.
        /// </remarks>
        /// <example>
        /// Use this like so:
        /// <code>
        ///     public class MyChild { public SomeChildProperty { get; set; } }
        ///     public class MyModel { public ChildObject { get; set; } }
        ///
        ///     Binding.Property((MyModel m) => m.ChildObject).Child(Binding.Property("SomeChildProperty"));
        /// </code>
        /// </example>
        /// <returns>The binding to the child property accessed through the current binding.</returns>
        /// <param name="binding">Binding to get the child value from this binding.</param>
        /// <typeparam name="TNewValue">The type of the child property value.</typeparam>
        public IndirectBinding <TNewValue> Child <TNewValue>(IndirectBinding <TNewValue> binding)
        {
            object bindingReference      = null;
            object childBindingReference = null;
            object context = null;
            EventHandler <EventArgs> eventHandler = null;
            EventHandler <EventArgs> valueChanged = (sender, e) =>
            {
                binding.RemoveValueChangedHandler(childBindingReference, eventHandler);
                eventHandler?.Invoke(sender, e);
                childBindingReference = binding.AddValueChangedHandler(GetValue(context), eventHandler);
            };

            return(new DelegateBinding <object, TNewValue>(
                       c => binding.GetValue(GetValue(context = c)),
                       (c, v) => binding.SetValue(GetValue(context = c), v),
                       addChangeEvent: (c, ev) =>
            {
                context = c;
                eventHandler = ev;
                bindingReference = AddValueChangedHandler(c, valueChanged);

                childBindingReference = binding.AddValueChangedHandler(GetValue(c), ev);
            },
                       removeChangeEvent: (c, ev) =>
            {
                binding.RemoveValueChangedHandler(childBindingReference, ev);
                RemoveValueChangedHandler(bindingReference, valueChanged);
            }
                       ));
        }
Beispiel #4
0
        /// <summary>
        /// Binds a control property to a <see cref="BindableWidget.DataContext"/> property
        /// </summary>
        /// <param name="control">Control to bind to.</param>
        /// <param name="controlProperty">Control property.</param>
        /// <param name="sourceProperty">Source property from the data context.</param>
        /// <param name="mode">Mode of the binding.</param>
        /// <param name="defaultControlValue">Default control value, if the control value is null.</param>
        /// <param name="defaultContextValue">Default context value, if the context value is null.</param>
        /// <typeparam name="TWidget">The type of control.</typeparam>
        /// <typeparam name="TContext">The type of the data context object.</typeparam>
        /// <typeparam name="TValue">The type of the property.</typeparam>
        public static DualBinding <TValue> BindDataContext <TWidget, TContext, TValue>(this TWidget control, Expression <Func <TWidget, TValue> > controlProperty, Expression <Func <TContext, TValue> > sourceProperty, DualBindingMode mode = DualBindingMode.TwoWay, TValue defaultControlValue = default(TValue), TValue defaultContextValue = default(TValue))
            where TWidget : IBindable
        {
            IndirectBinding <TValue> controlBinding = Binding.Property(controlProperty);

            IndirectBinding <TValue> sourceBinding = Binding.Property(sourceProperty);

            return(control.BindDataContext(controlBinding, sourceBinding, mode, defaultControlValue, defaultContextValue));
        }
Beispiel #5
0
        /// <summary>
        /// Executes a command retrieved using the specified <paramref name="commandBinding"/> from the <paramref name="dataContext"/>.
        /// </summary>
        /// <remarks>
        /// This helper method is useful for binding general events to fire an <see cref="ICommand"/> that is in your view model.
        /// The command will only be executed if its <see cref="ICommand.CanExecute"/> returns <c>true</c>.
        ///
        /// Most controls (e.g. <see cref="Eto.Forms.Button"/>) have a special Command parameter that can be set instead,
        /// which takes into account the enabled state of the command and will enable/disable the control automatically.
        /// </remarks>
        /// <example>
        /// This example will fire the MyModel.MyCommand when the mouse is down on the specified panel.
        /// The MyModel instance is based off the panel's current DataContext.
        /// <code>
        /// var panel = new Panel();
        /// panel.MouseDown += (sender, e) => Binding.ExecuteCommand(panel.DataContext, Binding.Property((MyModel m) => m.MyCommand));
        /// </code>
        /// </example>
        /// <param name="dataContext">Data context object to get the ICommand via the commandBinding.</param>
        /// <param name="commandBinding">Binding to get the ICommand from the data context</param>
        /// <param name="parameter">Parameter to pass to the command when executing or checking if it can execute.</param>
        public static void ExecuteCommand(object dataContext, IndirectBinding <ICommand> commandBinding, object parameter = null)
        {
            var command = commandBinding.GetValue(dataContext);

            if (command != null && command.CanExecute(parameter))
            {
                command.Execute(parameter);
            }
        }
Beispiel #6
0
        public DualBinding Bind(IndirectBinding controlBinding, object objectValue, IndirectBinding objectBinding, DualBindingMode mode = DualBindingMode.TwoWay, object defaultControlValue = null, object defaultContextValue = null)
        {
            var valueBinding = new ObjectBinding(objectValue, objectBinding)
            {
                SettingNullValue = defaultContextValue,
                GettingNullValue = defaultControlValue
            };

            return(Bind(controlBinding, valueBinding, mode));
        }
Beispiel #7
0
        /// <summary>
        /// Adds a new binding to the control with an indirect binding to the provided <paramref name="objectValue"/>
        /// </summary>
        /// <param name="controlBinding">Binding to get/set the value from the control.</param>
        /// <param name="objectValue">Object value to bind to.</param>
        /// <param name="objectBinding">Binding to get/set the value from the <paramref name="objectValue"/>.</param>
        /// <param name="mode">Mode of the binding.</param>
        /// <param name="defaultControlValue">Default control value to set to the objectValue, if the value of the control property is null.</param>
        /// <param name="defaultContextValue">Default context value to set to the control, if the objectValue or value of the objectBinding is null.</param>
        public DualBinding <T> Bind <T>(IndirectBinding <T> controlBinding, object objectValue, IndirectBinding <T> objectBinding, DualBindingMode mode = DualBindingMode.TwoWay, T defaultControlValue = default(T), T defaultContextValue = default(T))
        {
            var valueBinding = new ObjectBinding <object, T>(objectValue, objectBinding)
            {
                SettingNullValue = defaultContextValue,
                GettingNullValue = defaultControlValue
            };

            return(Bind(controlBinding, valueBinding, mode));
        }
Beispiel #8
0
 /// <summary>
 /// Creates a new indirect property binding using the specified <paramref name="propertyName"/>.
 /// </summary>
 /// <remarks>
 /// This supports single and multiple levels of property accessors in the model.
 /// </remarks>
 /// <example>
 /// Use this like so:
 /// <code>
 ///     public class MyChild { public SomeChildProperty { get; set; } }
 ///     public class MyModel {
 ///         public ChildObject { get; set; }
 ///         public int IntProperty { get; set; }
 ///     }
 ///
 ///     // direct property binding
 ///     Binding.Property("IntProperty");
 ///
 ///     // bind to a property of a child object of the view model
 ///     Binding.Property("ChildObject.SomeChildProperty");
 /// </code>
 /// </example>
 /// <param name="propertyName">Name of the property to bind to.</param>
 /// <param name="ignoreCase">True to ignore case of the property name, false to match the property name exactly.</param>
 /// <typeparam name="TValue">The type of the property.</typeparam>
 public static IndirectBinding <TValue> Property <TValue>(string propertyName, bool ignoreCase)
 {
     if (propertyName.IndexOf('.') > 0)
     {
         var props = propertyName.Split('.');
         IndirectBinding <object> prop = null;
         for (int i = 0; i < props.Length - 1; i++)
         {
             var pp = new PropertyBinding <object>(props[i], ignoreCase);
             prop = prop?.Child(pp) ?? pp;
         }
         return(prop.Child(new PropertyBinding <TValue>(props[props.Length - 1], ignoreCase)));
     }
     return(new PropertyBinding <TValue>(propertyName, ignoreCase));
 }
Beispiel #9
0
        /// <summary>
        /// Creates a new indirect property binding using the specified <paramref name="propertyExpression"/>.
        /// </summary>
        /// <remarks>
        /// This supports single and multiple levels of property accessors in the model.
        /// </remarks>
        /// <example>
        /// Use this like so:
        /// <code>
        ///     public class MyChild { public SomeChildProperty { get; set; } }
        ///     public class MyModel {
        ///         public ChildObject { get; set; }
        ///         public int IntProperty { get; set; }
        ///     }
        ///
        ///     // direct property binding
        ///     Binding.Property((MyModel m) => m.IntProperty);
        ///
        ///     // bind to a property of a child object of the view model
        ///     Binding.Property((MyModel m) => m.ChildObject.SomeChildProperty);
        /// </code>
        /// </example>
        /// <param name="propertyExpression">Expression of the property to bind to.</param>
        /// <typeparam name="T">The type of the model.</typeparam>
        /// <typeparam name="TValue">The property value type.</typeparam>
        public static IndirectBinding <TValue> Property <T, TValue>(Expression <Func <T, TValue> > propertyExpression)
        {
            var memberInfo = propertyExpression.GetMemberInfo();

            if (memberInfo == null)
            {
                // not a direct property expression, use a delegate to get value (but there will not be a way to set the value)
                var getValue = propertyExpression.Compile();
                return(Delegate(getValue));
            }
            var parentMember = memberInfo.Expression as MemberExpression;

            if (parentMember != null)
            {
                // go up parent heirarchy to get all the members
                var props = new List <MemberExpression>();
                do
                {
                    props.Add(parentMember);
                    var current = parentMember.Expression;

                    if (current.NodeType != ExpressionType.MemberAccess && current.NodeType != ExpressionType.Parameter)
                    {
                        return(Delegate(propertyExpression.Compile()));
                    }

                    parentMember = current as MemberExpression;
                } while (parentMember != null);

                props.Reverse();
                IndirectBinding <object> prop = null;
                foreach (var p in props)
                {
                    var pp = new PropertyBinding <object>(p.Member.Name);
                    prop = prop?.Child(pp) ?? pp;
                }
                // support multiple property access, e.g. m => m.Child.Property
                return(prop.Child(new PropertyBinding <TValue>(memberInfo.Member.Name)));
            }

            // not using the parameter of the expression
            if (memberInfo.Expression.NodeType != ExpressionType.Parameter)
            {
                return(Delegate(propertyExpression.Compile()));
            }

            return(new PropertyBinding <TValue>(memberInfo.Member.Name));
        }
Beispiel #10
0
        /// <summary>
        /// Binds to the specified child <paramref name="binding"/> of this binding.
        /// </summary>
        /// <remarks>
        /// This can be used to bind to child objects of your view model, for example
        /// <code>model.SomeProperty.ChildProperty</code>.
        /// </remarks>
        /// <example>
        /// Use this like so:
        /// <code>
        ///     public class MyChild { public SomeChildProperty { get; set; } }
        ///     public class MyModel { public ChildObject { get; set; } }
        ///
        ///     var model = new MyModel();
        ///     Binding.Property(model, (MyModel m) => m.ChildObject).Child(Binding.Property("SomeChildProperty"));
        /// </code>
        /// </example>
        /// <returns>The binding to the child property accessed through the current binding.</returns>
        /// <param name="binding">Binding to get the child value from this binding.</param>
        /// <typeparam name="TValue">The type of the child property value.</typeparam>
        public DirectBinding <TValue> Child <TValue>(IndirectBinding <TValue> binding)
        {
            object childBindingReference          = null;
            EventHandler <EventArgs> eventHandler = null;

            void valueChanged(object sender, EventArgs e)
            {
                binding.RemoveValueChangedHandler(childBindingReference, eventHandler);
                eventHandler?.Invoke(sender, e);
                childBindingReference = binding.AddValueChangedHandler(DataValue, eventHandler);
            }

            void setValueStruct(TValue v)
            {
                object parentValue = DataValue;

                binding.SetValue(parentValue, v);
                DataValue = (T)parentValue;
            }

            void setValueObject(TValue v) => binding.SetValue(DataValue, v);

            var isStruct = typeof(T).GetTypeInfo().IsValueType;

            return(new DelegateBinding <TValue>(
                       () => binding.GetValue(DataValue),
                       isStruct ? (Action <TValue>)setValueStruct : setValueObject,
                       addChangeEvent: ev =>
            {
                eventHandler = ev;
                DataValueChanged += valueChanged;
                childBindingReference = binding.AddValueChangedHandler(DataValue, ev);
            },
                       removeChangeEvent: ev =>
            {
                binding.RemoveValueChangedHandler(childBindingReference, ev);
                DataValueChanged -= valueChanged;
            }
                       ));
        }
Beispiel #11
0
        /// <summary>
        /// Binds to an object's <see cref="IBindable.DataContext"/> using the specified <paramref name="dataContextBinding"/>.
        /// </summary>
        /// <remarks>
        /// This creates a <see cref="DualBinding{TValue}"/> between a binding to the specified <paramref name="dataContextBinding"/> and this binding.
        /// Since the data context changes, the binding passed for the data context binding is an indirect binding, in that it is reused.
        /// The binding is added to the <see cref="IBindable.Bindings"/> collection.
        /// </remarks>
        /// <returns>A new dual binding that binds the <paramref name="dataContextBinding"/> to this control binding.</returns>
        /// <param name="dataContextBinding">Binding to get/set values from/to the control's data context.</param>
        /// <param name="mode">Dual binding mode.</param>
        /// <param name="defaultControlValue">Default control value.</param>
        /// <param name="defaultContextValue">Default context value.</param>
        public DualBinding <TValue> BindDataContext(IndirectBinding <TValue> dataContextBinding, DualBindingMode mode = DualBindingMode.TwoWay, TValue defaultControlValue = default(TValue), TValue defaultContextValue = default(TValue))
        {
            var control = DataItem;

            if (control == null)
            {
                throw new InvalidOperationException("Binding must be attached to a control");
            }
            var contextBinding = new BindableBinding <IBindable, object>(control, Binding.Delegate((IBindable w) => w.DataContext, null, (w, h) => w.DataContextChanged += h, (w, h) => w.DataContextChanged -= h));
            var valueBinding   = new ObjectBinding <object, TValue>(control.DataContext, dataContextBinding)
            {
                GettingNullValue = defaultControlValue,
                SettingNullValue = defaultContextValue,
                DataItem         = contextBinding.DataValue
            };
            DualBinding <TValue> binding = Bind(sourceBinding: valueBinding, mode: mode);

            contextBinding.DataValueChanged += delegate
            {
                ((ObjectBinding <object, TValue>)binding.Source).DataItem = contextBinding.DataValue;
            };
            control.Bindings.Add(contextBinding);
            return(binding);
        }
Beispiel #12
0
 public ImageTextCell(string imageProperty, string textProperty)
     : this()
 {
     ImageBinding = new PropertyBinding(imageProperty);
     TextBinding  = new PropertyBinding(textProperty);
 }
Beispiel #13
0
        /// <summary>
        /// Adds a new binding to the control with a direct value binding
        /// </summary>
        /// <param name="bindable">Bindable object to add the binding to</param>
        /// <param name="controlBinding">Binding to get/set the value from the control.</param>
        /// <param name="valueBinding">Value binding to get/set the value from another source.</param>
        /// <param name="mode">Mode of the binding</param>
        public static DualBinding <T> Bind <T>(this IBindable bindable, IndirectBinding <T> controlBinding, DirectBinding <T> valueBinding, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new BindableBinding <IBindable, T>(bindable, controlBinding);

            return(binding.Bind(sourceBinding: valueBinding, mode: mode));
        }
Beispiel #14
0
 /// <summary>
 /// Binds a control property to the <paramref name="source"/> object using the <paramref name="sourceBinding"/>.
 /// </summary>
 /// <param name="control">Control to bind to.</param>
 /// <param name="controlProperty">Control property expression.</param>
 /// <param name="source">Source object to bind to.</param>
 /// <param name="sourceBinding">Binding to get/set the value from the source.</param>
 /// <param name="mode">Mode of the binding.</param>
 /// <typeparam name="TWidget">The type of the control.</typeparam>
 /// <typeparam name="TSource">The type of the source object.</typeparam>
 /// <typeparam name="TValue">The type of the property.</typeparam>
 public static DualBinding <TValue> Bind <TWidget, TSource, TValue>(this TWidget control, Expression <Func <TWidget, TValue> > controlProperty, TSource source, IndirectBinding <TValue> sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay)
     where TWidget : IBindable
 {
     return(control.Bind(Binding.Property(controlProperty), source, sourceBinding, mode));
 }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the ChildBinding class
 /// </summary>
 /// <param name="parent">Binding from the parent to get the child</param>
 /// <param name="child">Binding for the child to get the actual value</param>
 public IndirectChildBinding(IndirectBinding <TParent> parent, IndirectBinding <TChild> child)
 {
     _parent = parent ?? throw new ArgumentNullException(nameof(parent));
     _child  = child ?? throw new ArgumentNullException(nameof(child));
 }
Beispiel #16
0
        /// <summary>
        /// Binds a control property to the <paramref name="source"/> object using the <paramref name="sourceBinding"/>.
        /// </summary>
        /// <param name="control">Control to bind to.</param>
        /// <param name="controlProperty">Control property expression.</param>
        /// <param name="source">Source object to bind to.</param>
        /// <param name="sourceBinding">Binding to get/set the value from the source.</param>
        /// <param name="mode">Mode of the binding.</param>
        /// <typeparam name="TWidget">The type of the control.</typeparam>
        /// <typeparam name="TSource">The type of the source object.</typeparam>
        /// <typeparam name="TValue">The type of the property.</typeparam>
        public static DualBinding <TValue> Bind <TWidget, TSource, TValue>(this TWidget control, Expression <Func <TWidget, TValue> > controlProperty, TSource source, IndirectBinding <TValue> sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay)
            where TWidget : IBindable
        {
            var controlExpression = controlProperty.GetMemberInfo();
            var binding           = control.Bind <TValue>(new PropertyBinding <TValue>(controlExpression.Member.Name), source, sourceBinding, mode);

            return(binding);
        }
Beispiel #17
0
 public ImageTextCell(int imageColumn, int textColumn)
     : this()
 {
     ImageBinding = new ColumnBinding(imageColumn);
     TextBinding  = new ColumnBinding(textColumn);
 }
Beispiel #18
0
        public DualBinding Bind(IndirectBinding controlBinding, DirectBinding valueBinding, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new ObjectBinding(this, controlBinding);

            return(binding.Bind(valueBinding: valueBinding, mode: mode));
        }
Beispiel #19
0
 /// <summary>
 /// Initializes a new instance of the ObjectBinding with the specified object and binding to get/set values with
 /// </summary>
 /// <param name="dataItem">object to get/set values from</param>
 /// <param name="innerBinding">binding to use to get/set the values from the dataItem</param>
 public ObjectBinding(object dataItem, IndirectBinding <TValue> innerBinding)
     : base(dataItem, innerBinding)
 {
 }
Beispiel #20
0
        /// <summary>
        /// Binds a control property to a <see cref="BindableWidget.DataContext"/> property
        /// </summary>
        /// <param name="control">Control to bind to.</param>
        /// <param name="controlProperty">Control property.</param>
        /// <param name="sourceBinding">Source binding to get/set the value on the data context.</param>
        /// <param name="mode">Mode of the binding.</param>
        /// <param name="defaultControlValue">Default control value, if the control value is null.</param>
        /// <param name="defaultContextValue">Default context value, if the context value is null.</param>
        /// <typeparam name="TWidget">The type of control.</typeparam>
        /// <typeparam name="TValue">The type of the property.</typeparam>
        public static DualBinding <TValue> BindDataContext <TWidget, TValue>(this TWidget control, Expression <Func <TWidget, TValue> > controlProperty, IndirectBinding <TValue> sourceBinding, DualBindingMode mode = DualBindingMode.TwoWay, TValue defaultControlValue = default(TValue), TValue defaultContextValue = default(TValue))
            where TWidget : IBindable
        {
            var controlExpression = controlProperty.GetMemberInfo();

            return(control.BindDataContext <TValue>(
                       new PropertyBinding <TValue>(controlExpression.Member.Name),
                       sourceBinding,
                       mode,
                       defaultControlValue,
                       defaultContextValue
                       ));
        }
Beispiel #21
0
        /// <summary>
        /// Adds a new binding from the control to its data context
        /// </summary>
        /// <param name="controlBinding">Binding to get/set the value from the control.</param>
        /// <param name="dataContextBinding">Binding to get/set the value from the <see cref="Control.DataContext"/>.</param>
        /// <param name="mode">Mode of the binding.</param>
        /// <param name="defaultControlValue">Default control value to set to the objectValue, if the value of the control property is null.</param>
        /// <param name="defaultContextValue">Default context value to set to the control, if the objectValue or value of the objectBinding is null.</param>
        public DualBinding <T> BindDataContext <T>(IndirectBinding <T> controlBinding, IndirectBinding <T> dataContextBinding, DualBindingMode mode = DualBindingMode.TwoWay, T defaultControlValue = default(T), T defaultContextValue = default(T))
        {
            var binding = new ControlBinding <Control, T>(this, controlBinding);

            return(binding.BindDataContext(dataContextBinding, mode, defaultControlValue, defaultContextValue));
        }
Beispiel #22
0
        /// <summary>
        /// Adds a new binding to the control with a direct value binding
        /// </summary>
        /// <param name="controlBinding">Binding to get/set the value from the control.</param>
        /// <param name="valueBinding">Value binding to get/set the value from another source.</param>
        /// <param name="mode">Mode of the binding</param>
        public DualBinding <T> Bind <T>(IndirectBinding <T> controlBinding, DirectBinding <T> valueBinding, DualBindingMode mode = DualBindingMode.TwoWay)
        {
            var binding = new ControlBinding <Control, T>(this, controlBinding);

            return(binding.Bind(sourceBinding: valueBinding, mode: mode));
        }
Beispiel #23
0
 public DualBinding <TValue> Bind(IndirectBinding <TValue> dataContextBinding, DualBindingMode mode = DualBindingMode.TwoWay, TValue defaultControlValue = default(TValue), TValue defaultContextValue = default(TValue))
 {
     return(BindDataContext(dataContextBinding, mode, defaultControlValue, defaultContextValue));
 }
Beispiel #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ControlBinding{T,TValue}"/> class.
 /// </summary>
 /// <param name="dataItem">Control the binding is attached to.</param>
 /// <param name="innerBinding">Inner binding.</param>
 public BindableBinding(T dataItem, IndirectBinding <TValue> innerBinding)
     : base(dataItem, innerBinding)
 {
 }
Beispiel #25
0
        public DualBinding Bind(IndirectBinding controlBinding, IndirectBinding dataContextBinding, DualBindingMode mode = DualBindingMode.TwoWay, object defaultControlValue = null, object defaultContextValue = null)
        {
            var binding = new ObjectBinding(this, controlBinding);

            return(binding.Bind(dataContextBinding, mode, defaultControlValue, defaultContextValue));
        }
Beispiel #26
0
 /// <summary>
 /// Binds to the specified child <paramref name="binding"/> of this binding.
 /// </summary>
 /// <remarks>
 /// This can be used to bind to child objects of your view model, for example
 /// <code>model.SomeProperty.ChildProperty</code>.
 /// </remarks>
 /// <example>
 /// Use this like so:
 /// <code>
 ///     public class MyChild { public SomeChildProperty { get; set; } }
 ///     public class MyModel { public ChildObject { get; set; } }
 ///
 ///     Binding.Property((MyModel m) => m.ChildObject).Child(Binding.Property("SomeChildProperty"));
 /// </code>
 /// </example>
 /// <returns>The binding to the child property accessed through the current binding.</returns>
 /// <param name="binding">Binding to get the child value from this binding.</param>
 /// <typeparam name="TNewValue">The type of the child property value.</typeparam>
 public IndirectBinding <TNewValue> Child <TNewValue>(IndirectBinding <TNewValue> binding)
 {
     return(new IndirectChildBinding <T, TNewValue>(this, binding));
 }
Beispiel #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ControlBinding{T,TValue}"/> class.
 /// </summary>
 /// <param name="dataItem">Control the binding is attached to.</param>
 /// <param name="innerBinding">Inner binding.</param>
 public ControlBinding(T dataItem, IndirectBinding <TValue> innerBinding)
     : base(dataItem, innerBinding)
 {
 }