예제 #1
0
        /// <summary>
        /// Initializes the dictionaries for properties and child objects
        /// and calls the main <c>Initialize</c> method to add the actual
        /// properties and child objects.
        /// </summary>
        private void Init()
        {
            properties   = new Dictionary <string, DataProperty>();
            childObjects = new Dictionary <string, DataObject>();
            actions      = new Dictionary <string, ActionProperty>();

            // add save action, and make it enabled only when the object is modified or doesn't track modifications
            SaveAction = new ActionProperty(this, Messages.Action_Save);
            Expression <Func <DataObject, bool> > saveEnabled = (obj) => obj != null && (obj.Modified || !obj.TrackModifications);

            SaveAction.SetComputedEnabled(saveEnabled, this);

            // add delete action, and make it enabled only when the object is not new
            DeleteAction = new ActionProperty(this, Messages.Action_Delete);
            Expression <Func <DataObject, bool> > deleteEnabled = (obj) => obj != null && !obj.IsNew;

            DeleteAction.SetComputedEnabled(deleteEnabled, this);

            ResetAction = new ActionProperty(this, Messages.Action_Reset);

            // call subclass initialization in a separate method
            // to make sure base initialization is always called
            Initialize();
            OnInitialized();
        }
예제 #2
0
        /// <summary>
        /// Additional initialization after all properties are constructed
        /// </summary>
        protected override void OnInitialized()
        {
            base.OnInitialized();
            SearchAction = new ActionProperty(this, Messages.Action_Search);
            SelectAction = new ActionProperty(this, Messages.Action_Select);

            Expression <Func <DataListObject, bool> > xSel = lst => lst.SelectedRows.Any();

            SelectAction.SetComputedEnabled(xSel, this);

            foreach (DataProperty p in Properties)
            {
                p.Column = ColumnCount++;
            }
            data.CollectionChanged += (s, e) =>
            {
                FireCollectionChange(e);
                if (e.Action == NotifyCollectionChangedAction.Reset ||
                    e.OldItems != null && e.OldItems.Cast <DataRow>().Any(r => r.Selected) ||
                    e.NewItems.Cast <DataRow>().Any(r => r.Selected))
                {
                    FireSelectionChanged();
                }
            };
        }
예제 #3
0
 /// <summary>
 /// Adds the specified action to the data object.
 /// </summary>
 /// <param name="action">The action to add to the data object.</param>
 internal void AddAction(ActionProperty action)
 {
     actions[action.Name] = action;
 }