コード例 #1
0
ファイル: Control.binding.cs プロジェクト: CheckTech/Eto
        /// <summary>
        /// Adds a new binding with the control and the the control's current data context
        /// </summary>
        /// <remarks>
        /// This binds to a property of the <see cref="Control.DataContext"/>, which will return the topmost value
        /// up the control hierarchy.  For example, you can set the DataContext of your form or panel, and then bind to properties
        /// of that context on any of the child controls such as a text box, etc.
        /// </remarks>
        /// <param name="controlPropertyName">Property on the control to update</param>
        /// <param name="dataContextPropertyName">Property on the control's <see cref="Control.DataContext"/> to bind to the control</param>
        /// <param name="mode">Mode of the binding</param>
        /// <param name="defaultControlValue">Default value to set to the control when the value from the DataContext is null</param>
        /// <param name="defaultContextValue">Default value to set to the DataContext property when the control value is null</param>
        /// <returns>A new instance of the DualBinding class that is used to control the binding</returns>
        public DualBinding <T> BindDataContext <T>(string controlPropertyName, string dataContextPropertyName, DualBindingMode mode = DualBindingMode.TwoWay, T defaultControlValue = default(T), T defaultContextValue = default(T))
        {
            var dataContextBinding = new PropertyBinding <T>(dataContextPropertyName);
            var controlBinding     = new PropertyBinding <T>(controlPropertyName);

            return(BindDataContext(controlBinding, dataContextBinding, mode, defaultControlValue, defaultContextValue));
        }
コード例 #2
0
ファイル: Control.binding.cs プロジェクト: sami1971/Eto
        /// <summary>
        /// Adds a new binding with the control and the the control's current data context
        /// </summary>
        /// <remarks>
        /// This binds to a property of the <see cref="Control.DataContext"/>, which will return the topmost value
        /// up the control hierarchy.  For example, you can set the DataContext of your form or panel, and then bind to properties
        /// of that context on any of the child controls such as a text box, etc.
        /// </remarks>
        /// <param name="controlPropertyName">Property on the control to update</param>
        /// <param name="dataContextPropertyName">Property on the control's <see cref="Control.DataContext"/> to bind to the control</param>
        /// <param name="mode">Mode of the binding</param>
        /// <param name="defaultControlValue">Default value to set to the control when the value from the DataContext is null</param>
        /// <param name="defaultContextValue">Default value to set to the DataContext property when the control value is null</param>
        /// <returns>A new instance of the DualBinding class that is used to control the binding</returns>
        public DualBinding Bind(string controlPropertyName, string dataContextPropertyName, DualBindingMode mode = DualBindingMode.TwoWay, object defaultControlValue = null, object defaultContextValue = null)
        {
            var dataContextBinding = new PropertyBinding(dataContextPropertyName);
            var controlBinding     = new PropertyBinding(controlPropertyName);

            return(Bind(controlBinding, dataContextBinding, mode, defaultControlValue, defaultContextValue));
        }
コード例 #3
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
        {
            var controlExpression = controlProperty.GetMemberInfo();
            IndirectBinding <TValue> controlBinding;

            if (controlExpression != null)
            {
                controlBinding = new PropertyBinding <TValue>(controlExpression.Member.Name);
            }
            else
            {
                controlBinding = new DelegateBinding <TWidget, TValue>(controlProperty.Compile());
            }

            var sourceExpression = sourceProperty.GetMemberInfo();
            IndirectBinding <TValue> sourceBinding;

            if (sourceExpression != null)
            {
                sourceBinding = new PropertyBinding <TValue>(sourceExpression.Member.Name);
            }
            else
            {
                sourceBinding = new DelegateBinding <TContext, TValue>(sourceProperty.Compile());
            }
            return(control.BindDataContext(controlBinding, sourceBinding, mode, defaultControlValue, defaultContextValue));
        }
コード例 #4
0
ファイル: Binding.helpers.cs プロジェクト: philstopford/Eto
 /// <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));
 }
コード例 #5
0
ファイル: Binding.helpers.cs プロジェクト: philstopford/Eto
        /// <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));
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Forms.ImageViewCell"/> class when binding to properties via reflection.
 /// </summary>
 /// <param name="property">Property to bind to in each data item.</param>
 public ImageViewCell(string property)
 {
     Binding = new PropertyBinding <Image>(property);
 }
コード例 #7
0
 public TextBoxCell(string property)
     : this()
 {
     Binding = new PropertyBinding(property);
 }
コード例 #8
0
ファイル: TextBoxCell.cs プロジェクト: yaram/Eto
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Forms.TextBoxCell"/> class binding the text value to the specified <paramref name="property"/> of the data store.
 /// </summary>
 /// <param name="property">Name of the property to bind to in the data store.</param>
 public TextBoxCell(string property)
 {
     Binding = new PropertyBinding <string>(property);
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Forms.ProgressCell"/> class with the specified property to bind to.
 /// </summary>
 /// <param name="property">Property to bind the value of the progress bar to.</param>
 /// <param name="ignoreCase">True to ignore case for the property, false to be case sensitive. Default is true.</param>
 public ProgressCell(string property, bool ignoreCase = true)
 {
     Binding = new PropertyBinding <float?>(property, ignoreCase);
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Forms.CheckBoxCell"/> class with the specified property to bind to.
 /// </summary>
 /// <param name="property">Property to bind the value of the check box to.</param>
 public CheckBoxCell(string property)
     : this()
 {
     Binding = new PropertyBinding <bool?>(property);
 }
コード例 #11
0
ファイル: ImageTextCell.cs プロジェクト: yaram/Eto
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Forms.ImageTextCell"/> class when binding to properties via reflection.
 /// </summary>
 /// <param name="imageProperty">Name of the image property in the data item.</param>
 /// <param name="textProperty">Name of the text property in the data item.</param>
 public ImageTextCell(string imageProperty, string textProperty)
 {
     ImageBinding = new PropertyBinding <Image>(imageProperty);
     TextBinding  = new PropertyBinding <string>(textProperty);
 }
コード例 #12
0
ファイル: ImageViewCell.cs プロジェクト: modulexcite/Eto-1
 public ImageViewCell(string property)
     : this()
 {
     Binding = new PropertyBinding(property);
 }
コード例 #13
0
ファイル: ImageTextCell.cs プロジェクト: modulexcite/Eto-1
 public ImageTextCell(string imageProperty, string textProperty)
     : this()
 {
     ImageBinding = new PropertyBinding(imageProperty);
     TextBinding  = new PropertyBinding(textProperty);
 }
コード例 #14
0
ファイル: ComboBoxCell.cs プロジェクト: yaram/Eto
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Forms.ComboBoxCell"/> class with the specified property to bind to.
 /// </summary>
 /// <param name="property">Property to bind the value of the combo box to.</param>
 public ComboBoxCell(string property)
     : this()
 {
     Binding = new PropertyBinding <object>(property);
 }