Exemplo n.º 1
0
        /// <summary>
        /// Updates the check box's Checked state based on the boolean property value.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            // let the base handle everything except value change
            base.UpdateElement(change - PropertyChange.Value);
            if (property == null)
            {
                return;
            }

            bool check = property.InternalValue is bool && (bool)property.InternalValue;

            if (change.IncludesValue())
            {
                ((CheckBox)control).Checked = check;
                DataListObject list = property.GetParent() as DataListObject;
                if (list != null)
                {
                    SetControlAttribute("row", "" + list.CurrentRow);
                }
            }
            // Update property value after binding to make it in sync with the checkbox.
            // Otherwise if the checkbox stays unchecked it will not post a false value
            // and the property value will remain whatever it was, e.g. null.
            if (change == PropertyChange.All && !check)
            {
                PostedValue = "false";
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the toggle button based on the given property change.
        /// If the property is not required the toggle button will allow three states
        /// to support an indeterminate state when the property value is not set.
        /// Otherwise turns the toggle button on or off based on the Boolean value of the property.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null)
            {
                return;
            }

            if (change.IncludesRequired())
            {
                ((ToggleButton)element).IsThreeState = !property.Required;
            }
            if (change.IncludesValue())
            {
                bool?  check = null;
                object val   = property.InternalValue;
                if (val is bool)
                {
                    check = (bool)val;
                }
                else
                {
                    check = val as bool?;
                }
                ((ToggleButton)element).IsChecked = check;
            }
        }
        /// <summary>
        /// Updates the text of the text block to the property value formatted
        /// according to the property's DisplayString format.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null) return;

            if (change.IncludesValue())
            {
                ((TextBlock)element).Text = property.DisplayStringValue;
            }
        }
        /// <summary>
        /// Updates the text of the hyperlink to the property value formatted
        /// according to the property's DisplayString format.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null) return;

            if (change.IncludesValue())
            {
                Hyperlink lnk = (Hyperlink)element;
                lnk.Inlines.Clear();
                lnk.Inlines.Add(property.DisplayStringValue);
            }
        }
        /// <summary>
        /// Updates the text of the text box to the property value formatted
        /// according to the property's EditString format if editable or DisplayString if not editable.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null)
            {
                return;
            }

            if (change.IncludesValue())
            {
                ((TextBox)element).Text = property.GetStringValue(property.Editable ? ValueFormat.EditString : ValueFormat.DisplayString, row);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the text of the text block to the property value formatted
        /// according to the property's DisplayString format.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null)
            {
                return;
            }

            if (change.IncludesValue())
            {
                ((TextBlock)element).Text = property.DisplayStringValue;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Updates the text of the text box to the property value formatted
        /// according to the property's EditString format if editable or DisplayString if not editable.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null)
            {
                return;
            }

            if (change.IncludesValue())
            {
                ((PasswordBox)element).Password = property.Editable ? property.EditStringValue : property.DisplayStringValue;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Updates the text of a text control to the property value formatted
        /// according to the property's EditString format if editable or DisplayString if not editable.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null)
            {
                return;
            }

            if (change.IncludesValue() && control is ITextControl txtCtl)
            {
                txtCtl.Text = property.GetStringValue(control is IEditableTextControl && property.Editable ?
                                                      ValueFormat.EditString : ValueFormat.DisplayString,
                                                      row);
            }
        }
        /// <summary>
        /// Updates the text of the hyperlink to the property value formatted
        /// according to the property's DisplayString format.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null)
            {
                return;
            }

            if (change.IncludesValue())
            {
                Hyperlink lnk = (Hyperlink)element;
                lnk.Inlines.Clear();
                lnk.Inlines.Add(property.GetStringValue(ValueFormat.DisplayString, row));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Updates the text of a text control to the property value formatted
        /// according to the property's EditString format if editable or DisplayString if not editable.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null)
            {
                return;
            }

            ITextControl txtCtl = control as ITextControl;

            if (change.IncludesValue() && txtCtl != null)
            {
                txtCtl.Text = control is IEditableTextControl && property.Editable ?
                              property.EditStringValue : property.DisplayStringValue;
            }
        }
Exemplo n.º 11
0
            /// <summary>
            /// Updates the control and fills the items and selection listboxes.
            /// </summary>
            /// <param name="change">The property change.</param>
            protected override void UpdateElement(PropertyChange change)
            {
                base.UpdateElement(change);

                if (change.IncludesItems() || change.IncludesValue())
                {
                    // update selection list
                    ListBox lbxSelection = (control as BasePickListControl).lbx_Selection;
                    lbxSelection.Items.Clear();

                    IEnumerable values = property.IsMultiValued ?
                                         property.InternalValue as IEnumerable :
                                         new object[] { property.InternalValue };

                    if (values != null)
                    {
                        foreach (object i in values)
                        {
                            lbxSelection.Items.Add(new ListItem(
                                                       property.ValueToString(i, ValueFormat.DisplayString),
                                                       property.ValueToString(i, ValueFormat.EditString)));
                        }
                    }

                    // update items list
                    ListBox lbxItems = (control as BasePickListControl).lbx_Items;
                    lbxItems.Items.Clear();

                    IEnumerable items = property.ItemsProvider != null?property.ItemsProvider(null) : null;

                    if (items != null)
                    {
                        foreach (object i in items)
                        {
                            string   value = property.ValueToString(i, ValueFormat.EditString);
                            ListItem li    = lbxSelection.Items.FindByValue(value);
                            if (li == null)
                            {
                                lbxItems.Items.Add(new ListItem(
                                                       property.ValueToString(i, ValueFormat.DisplayString),
                                                       value));
                            }
                        }
                    }
                }
            }
        /// <summary>
        /// Updates the toggle button based on the given property change.
        /// If the property is not required the toggle button will allow three states
        /// to support an indeterminate state when the property value is not set.
        /// Otherwise turns the toggle button on or off based on the Boolean value of the property.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null) return;

            if (change.IncludesRequired())
            {
                ((ToggleButton)element).IsThreeState = !property.Required;
            }
            if (change.IncludesValue())
            {
                bool? check = null;
                object val = property.InternalValue;
                if (val is bool) check = (bool)val;
                else check = val as bool?;
                ((ToggleButton)element).IsChecked = check;
            }
        }
        /// <summary>
        /// Updates the selected date of the date picker.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null)
            {
                return;
            }

            if (change.IncludesValue())
            {
                DateTimeProperty dtp = property as DateTimeProperty;
                if (dtp != null)
                {
                    ((DatePicker)element).SelectedDate = dtp.Value;
                }
                else
                {
                    ((DatePicker)element).Text = property.GetStringValue(property.Editable ? ValueFormat.EditString : ValueFormat.DisplayString, row);
                }
            }
        }
        /// <summary>
        /// Updates the check box's Checked state based on the boolean property value.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            // let the base handle everything except value change
            base.UpdateElement(change - PropertyChange.Value);
            if (property == null) return;

            bool check = property.InternalValue is bool && (bool)property.InternalValue;
            if (change.IncludesValue())
            {
                ((CheckBox)control).Checked = check;
                DataListObject list = property.GetParent() as DataListObject;
                if (list != null)
                    SetControlAttribute("row", "" + list.CurrentRow);
            }
            // Update property value after binding to make it in sync with the checkbox.
            // Otherwise if the checkbox stays unchecked it will not post a false value
            // and the property value will remain whatever it was, e.g. null.
            if (change == PropertyChange.All && !check)
            {
                PostedValue = "false";
            }
        }
        /// <summary>
        /// Updates the check box's Checked state based on the boolean property value.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            // let the base handle everything except value change
            base.UpdateElement(change - PropertyChange.Value);
            if (property == null)
            {
                return;
            }

            object val   = property.GetValue(ValueFormat.Internal, row);
            bool   check = val is bool b && b;

            if (change.IncludesValue())
            {
                ((CheckBox)control).Checked = check;
            }
            // Update property value after binding to make it in sync with the checkbox.
            // Otherwise if the checkbox stays unchecked it will not post a false value
            // and the property value will remain whatever it was, e.g. null.
            if (change == PropertyChange.All && !check)
            {
                PostedValue = "false";
            }
        }
            /// <summary>
            /// Updates the control and fills the items and selection listboxes.
            /// </summary>
            /// <param name="change">The property change.</param>
            protected override void UpdateElement(PropertyChange change)
            {
                base.UpdateElement(change);

                if (change.IncludesItems() || change.IncludesValue())
                {
                    // update selection list
                    ListBox lbxSelection = (control as BasePickListControl).lbx_Selection;
                    lbxSelection.Items.Clear();

                    IEnumerable values = property.IsMultiValued ?
                        property.InternalValue as IEnumerable :
                        new object[] { property.InternalValue };

                    if (values != null) foreach (object i in values)
                    {
                        lbxSelection.Items.Add(new ListItem(
                            property.ValueToString(i, ValueFormat.DisplayString),
                            property.ValueToString(i, ValueFormat.EditString)));
                    }

                    // update items list
                    ListBox lbxItems = (control as BasePickListControl).lbx_Items;
                    lbxItems.Items.Clear();

                    IEnumerable items = property.ItemsProvider != null ? property.ItemsProvider(null) : null;
                    if (items != null) foreach (object i in items)
                    {
                        string value = property.ValueToString(i, ValueFormat.EditString);
                        ListItem li = lbxSelection.Items.FindByValue(value);
                        if (li == null)
                        {
                            lbxItems.Items.Add(new ListItem(
                                property.ValueToString(i, ValueFormat.DisplayString),
                                value));
                        }
                    }
                }
            }
Exemplo n.º 17
0
        /// <summary>
        /// Updates the list control based on the given property change.
        /// Updates the list of possible items based on the values provided by the property
        /// and inserts a blank item for a drop down list if the property is editable and not required.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            // let the base handle everything except value change
            base.UpdateElement(change - PropertyChange.Value);
            ListControl list = control as ListControl;

            if (property == null || list == null)
            {
                return;
            }

            object  val        = property.InternalValue;
            IList   lst        = val == null ? new ArrayList() : val as IList;
            ListBox lb         = control as ListBox;
            bool    isMultiVal = lst != null && (control is CheckBoxList ||
                                                 lb != null && lb.SelectionMode == ListSelectionMode.Multiple);
            DropDownList dl = control as DropDownList;

            if (change.IncludesItems() || // if items list changed,
                isMultiVal && change.IncludesEditable() || // or control shows all items and Editable changed,
                dl != null && change.IncludesRequired() || // or control is DropDownList and Required changed,
                change.IncludesValue())    // or property value changed
            {
                // get the list of items to show
                IEnumerable src = null;
                if (isMultiVal && !property.Editable)
                {
                    src = lst;
                }
                else if (property.ItemsProvider != null)
                {
                    src = property.ItemsProvider(null);
                }

                list.Items.Clear(); // clear control's item collection

                // for DropDownList, add special items in case when not Required or Required and has no value
                if (dl != null && !property.Required)
                {
                    list.Items.Add(new ListItem("", property.NullString));
                }
                if (dl != null && property.Required && property.IsNull())
                {
                    list.Items.Add(new ListItem("Select Value...", ""));
                }
                int insertionPoint = list.Items.Count;

                // add items to show
                if (src != null)
                {
                    foreach (object i in src)
                    {
                        ListItem li = new ListItem(property.ValueToString(i, ValueFormat.DisplayString),
                                                   property.ValueToString(i, ValueFormat.EditString));
                        list.Items.Add(li);
                        li.Selected = src == lst; // if items are values, mark them as selected
                    }
                }

                // if not showing only values, make sure the values are present in the list and mark them as selected
                if (src != lst)
                {
                    IEnumerable values = isMultiVal ? lst : new object[] { (lst != null && lst.Count > 0) ? lst[0] : property.InternalValue };
                    foreach (object i in values)
                    {
                        ListItem li = list.Items.FindByValue(property.ValueToString(i, ValueFormat.EditString));
                        if (li == null) // add values not in list
                        {
                            li = new ListItem(property.ValueToString(i, ValueFormat.DisplayString),
                                              property.ValueToString(i, ValueFormat.EditString));
                            li.Attributes["disabled"] = "disabled";; // disable items not included in the list of expected values
                            list.Items.Insert(insertionPoint++, li); // insert them after special items and before expected values
                        }
                        li.Selected = true;
                    }
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Updates the selector based on the given property change.
        /// Updates the list of possible items based on the values provided by the property
        /// and inserts a blank item for a combo box if the property is editable and not required.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            Selector sel = element as Selector;

            if (property == null || sel == null)
            {
                return;
            }

            object   val = property.InternalValue;
            IList    lst = val as IList;
            ListBox  lb  = element as ListBox;
            ComboBox cb  = element as ComboBox;

            if (change.IncludesItems() ||
                lb != null && change.IncludesEditable() ||
                cb != null && change.IncludesRequired())
            {
                sel.Items.Clear();
                IEnumerable src = null;
                if (lb != null && !property.Editable && lst != null)
                {
                    src = lst;
                }
                else if (property.ItemsProvider != null)
                {
                    src = property.ItemsProvider(null);
                }

                // for non-required drop down lists add null string option
                if (cb != null && !cb.IsEditable && !property.Required)
                {
                    sel.Items.Add(property.NullString);
                }

                // add items explicitly. Don't use sel.ItemSource since src is not observable
                if (src != null)
                {
                    foreach (object item in src)
                    {
                        sel.Items.Add(item);
                    }
                }
            }
            if (change.IncludesValue() || change.IncludesItems())
            {
                if (lb != null && lst != null && lb.SelectionMode != SelectionMode.Single)
                {
                    lb.SelectedItems.Clear();
                    foreach (object item in lst)
                    {
                        lb.SelectedItems.Add(item);
                    }
                }
                else if (lst != null && lst.Count > 0)
                {
                    sel.SelectedItem = lst[0];
                }
                else
                {
                    sel.SelectedItem = val;
                }

                if (cb != null && cb.IsEditable)
                {
                    cb.Text = property.EditStringValue;
                }
            }
        }
        /// <summary>
        /// Updates the selector based on the given property change.
        /// Updates the list of possible items based on the values provided by the property
        /// and inserts a blank item for a combo box if the property is editable and not required.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            Selector sel = element as Selector;

            if (property == null || sel == null) return;

            object val = property.InternalValue;
            IList lst = val as IList;
            ListBox lb = element as ListBox;
            ComboBox cb = element as ComboBox;

            if (change.IncludesItems() ||
                lb != null && change.IncludesEditable() ||
                cb != null && change.IncludesRequired())
            {
                sel.Items.Clear();
                IEnumerable src = null;
                if (lb != null && !property.Editable && lst != null) src = lst;
                else if (property.ItemsProvider != null) src = property.ItemsProvider(null);

                // for non-required drop down lists add null string option
                if (cb != null && !cb.IsEditable && !property.Required)
                    sel.Items.Add(property.NullString);

                // add items explicitly. Don't use sel.ItemSource since src is not observable
                if (src != null) foreach (object item in src) sel.Items.Add(item);
            }
            if (change.IncludesValue() || change.IncludesItems())
            {
                if (lb != null && lst != null && lb.SelectionMode != SelectionMode.Single)
                {
                    lb.SelectedItems.Clear();
                    foreach (object item in lst) lb.SelectedItems.Add(item);
                }
                else if (lst != null && lst.Count > 0) sel.SelectedItem = lst[0];
                else sel.SelectedItem = val;

                if (cb != null && cb.IsEditable) cb.Text = property.EditStringValue;
            }
        }
        /// <summary>
        /// Updates the text of a text control to the property value formatted
        /// according to the property's EditString format if editable or DisplayString if not editable.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            base.UpdateElement(change);
            if (property == null) return;

            ITextControl txtCtl = control as ITextControl;
            if (change.IncludesValue() && txtCtl != null)
            {
                txtCtl.Text = control is IEditableTextControl && property.Editable ?
                    property.EditStringValue : property.DisplayStringValue;
            }
        }
        /// <summary>
        /// Updates the list control based on the given property change.
        /// Updates the list of possible items based on the values provided by the property
        /// and inserts a blank item for a drop down list if the property is editable and not required.
        /// </summary>
        /// <param name="change">The property change.</param>
        protected override void UpdateElement(PropertyChange change)
        {
            // let the base handle everything except value change
            base.UpdateElement(change - PropertyChange.Value);
            ListControl list = control as ListControl;

            if (property == null || list == null) return;

            object val = property.InternalValue;
            IList lst = val == null ? new ArrayList() : val as IList;
            ListBox lb = control as ListBox;
            bool isMultiVal = lst != null && (control is CheckBoxList
                || lb != null && lb.SelectionMode == ListSelectionMode.Multiple);
            DropDownList dl = control as DropDownList;

            if (change.IncludesItems() // if items list changed,
                || isMultiVal && change.IncludesEditable() // or control shows all items and Editable changed,
                || dl != null && change.IncludesRequired() // or control is DropDownList and Required changed,
                || change.IncludesValue()) // or property value changed
            {
                // get the list of items to show
                IEnumerable src = null;
                if (isMultiVal && !property.Editable) src = lst;
                else if (property.ItemsProvider != null) src = property.ItemsProvider(null);

                list.Items.Clear(); // clear control's item collection

                // for DropDownList, add special items in case when not Required or Required and has no value
                if (dl != null && !property.Required)
                    list.Items.Add(new ListItem("", property.NullString));
                if (dl != null && property.Required && property.IsNull())
                    list.Items.Add(new ListItem("Select Value...", ""));
                int insertionPoint = list.Items.Count;

                // add items to show
                if (src != null)
                {
                    foreach (object i in src)
                    {
                        ListItem li = new ListItem(property.ValueToString(i, ValueFormat.DisplayString),
                            property.ValueToString(i, ValueFormat.EditString));
                        list.Items.Add(li);
                        li.Selected = src == lst; // if items are values, mark them as selected
                    }
                }

                // if not showing only values, make sure the values are present in the list and mark them as selected
                if (src != lst)
                {
                    IEnumerable values = isMultiVal ? lst : new object[] { (lst != null && lst.Count > 0) ? lst[0] : property.InternalValue };
                    foreach (object i in values)
                    {
                        ListItem li = list.Items.FindByValue(property.ValueToString(i, ValueFormat.EditString));
                        if (li == null) // add values not in list
                        {
                            li = new ListItem(property.ValueToString(i, ValueFormat.DisplayString),
                                property.ValueToString(i, ValueFormat.EditString));
                            li.Attributes["disabled"] = "disabled"; ; // disable items not included in the list of expected values
                            list.Items.Insert(insertionPoint++, li); // insert them after special items and before expected values
                        }
                        li.Selected = true;
                    }
                }
            }
        }