Ejemplo n.º 1
0
        /// <summary>
        /// Control's OnPropertyBound event handler extension.
        /// </summary>
        /// <param name="prop">Property object.</param>
        public virtual void OnPropertyBound(DateTimeProperty prop)
        {
            BasePropertyBinding pb = WebPropertyBinding.Create(txt_DateTime) as BasePropertyBinding;

            if (pb != null)
            {
                pb.BindTo(prop);
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public override void BindTo(ViewModel viewModel)
        {
            bool bind = viewModel != null;

            if ((viewModel ?? Model) is SearchViewModel svm)
            {
                if (btn_Select != null && bind && svm.Params != null)
                {
                    btn_Select.Visible = (svm.Params[ViewParams.SelectionMode.Param] != null);
                }

                // subscribe to property change events on the data list object
                if (bind)
                {
                    if (svm.List != null)
                    {
                        svm.List.PropertyChanged += OnListPropertyChanged;
                    }
                    // persist the object in session
                    ListObj = svm.List;
                }
                else
                {
                    if (svm.List != null)
                    {
                        svm.List.PropertyChanged -= OnListPropertyChanged;
                    }
                }
                OnModelPropertyChanged(svm, new PropertyChangedEventArgs(SearchViewModel.CriteriaCollapsedProperty));
                OnListPropertyChanged(bind ? svm.List : null, new PropertyChangedEventArgs(nameof(DataListObject.AppliedCriteria)));

                if (svm.List != null && grd_Results != null)
                {
                    if (svm.List.CriteriaObject != null && ucl_Criteria != null)
                    {
                        ucl_Criteria.DataBind();
                        WebPropertyBinding.BindToObject(ucl_Criteria, bind ? svm.List.CriteriaObject : null);
                        if (svm.List.AppliedCriteria != null) // recalculate applied criteria with updated labels after binding
                        {
                            svm.List.AppliedCriteria = svm.List.CriteriaObject.GetFieldCriteriaSettings();
                        }
                    }
                    if (grd_Results != null)
                    {
                        grd_Results.AutoGenerateSelectButton = ViewParams.SelectionMode.Single.Equals(svm.Params[ViewParams.SelectionMode.Param]);
                        WebPropertyBinding.BindToList(grd_Results, bind ? svm.List : null);
                    }
                }
            }
            base.BindTo(viewModel);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Binds the view to its model, or unbinds the current model if null is passed.
        /// </summary>
        /// <param name="viewModel">Model to bind the view to</param>
        public override void BindTo(ViewModel viewModel)
        {
            bool            bind = viewModel != null;
            SearchViewModel svm  = (bind ? viewModel : this.Model) as SearchViewModel;

            if (svm != null)
            {
                if (btn_Select != null && bind && svm.Params != null)
                {
                    btn_Select.Visible = (svm.Params[ViewParams.SelectionMode.Param] != null);
                }

                // subscribe to property change events on the data list object
                if (bind)
                {
                    if (svm.List != null)
                    {
                        svm.List.PropertyChanged += OnListPropertyChanged;
                    }
                    // persist the object in session
                    listObj = svm.List;
                }
                else
                {
                    if (svm.List != null)
                    {
                        svm.List.PropertyChanged -= OnListPropertyChanged;
                    }
                }
                OnModelPropertyChanged(svm, new PropertyChangedEventArgs(SearchViewModel.CriteriaCollapsedProperty));
                OnListPropertyChanged(bind ? svm.List : null, new PropertyChangedEventArgs(DataListObject.AppliedCriteriaProperty));

                if (svm.List != null && grd_Results != null)
                {
                    if (svm.List.CriteriaObject != null && ucl_Criteria != null)
                    {
                        ucl_Criteria.DataBind();
                        WebPropertyBinding.BindToObject(ucl_Criteria, bind ? svm.List.CriteriaObject : null);
                    }
                    if (grd_Results != null)
                    {
                        grd_Results.AutoGenerateSelectButton = ViewParams.SelectionMode.Single.Equals(svm.Params[ViewParams.SelectionMode.Param]);
                        WebPropertyBinding.BindToList(grd_Results, bind ? svm.List : null);
                    }
                }
            }
            base.BindTo(viewModel);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Binds the view to its model, or unbinds the current model if null is passed.
        /// </summary>
        /// <param name="viewModel">Model to bind the view to</param>
        public override void BindTo(ViewModel viewModel)
        {
            bool             bind = viewModel != null;
            DetailsViewModel dvm  = (bind ? viewModel : this.Model) as DetailsViewModel;

            if (dvm != null)
            {
                if (dvm.DetailsObject != null && pnl_Object != null)
                {
                    pnl_Object.DataBind();
                    WebPropertyBinding.BindToObject(pnl_Object, bind ? dvm.DetailsObject : null);
                }
                if (bind)
                {
                    dataObj = dvm.DetailsObject;       // persist the object in session
                }
            }
            base.BindTo(viewModel);
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public override void BindTo(ViewModel viewModel)
        {
            bool bind = viewModel != null;

            if ((viewModel ?? Model) is DetailsViewModel dvm)
            {
                if (dvm.DetailsObject != null && pnl_Object != null)
                {
                    pnl_Object.DataBind();
                    WebPropertyBinding.BindToObject(pnl_Object, bind ? dvm.DetailsObject : null);
                }
                if (bind)
                {
                    DataObj = dvm.DetailsObject;       // persist the object in session
                }
                else
                {
                    dvm.DetailsObject = null;  // detach view model from persisted object
                }
            }
            base.BindTo(viewModel);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Binds a control or all of its child controls (e.g. for a containing panel)
        /// to the given data object (or its child object)
        /// as specified by the controls' Property and ChildObject attributes.
        /// </summary>
        /// <param name="ctl">Control to bind to the given data object.</param>
        /// <param name="obj">Data object to bind the control to.</param>
        /// <param name="bindCurrentRow">For list objects specifies whether to bind the whole list or just the current row.</param>
        public static void BindToObject(Control ctl, DataObject obj, bool bindCurrentRow)
        {
            if (obj == null || ctl == null)
            {
                return;
            }

            AttributeCollection attr = GetControlAttributes(ctl);
            string     childPath     = attr != null ? attr[AttrChildObject] : null;
            DataObject cObj          = FindChildObject(obj, childPath);

            obj = cObj as DataObject;
            string propertyName = attr != null ? attr[AttrProperty] : null;

            if (obj != null && propertyName != null)
            {
                WebPropertyBinding binding = Create(ctl) as WebPropertyBinding;
                if (binding != null)
                {
                    binding.BindTo(obj[propertyName]);
                }
                // remove attributes that are no longer needed to minimize HTML
                attr.Remove(AttrChildObject);
                attr.Remove(AttrProperty);
            }
            else if (cObj is DataListObject && !bindCurrentRow)
            {
                BindToList(ctl, (DataListObject)cObj);
            }
            else
            {
                foreach (Control c in ctl.Controls)
                {
                    BindToObject(c, obj, bindCurrentRow);
                }
            }
        }