示例#1
0
        public static void DataGridItemPropertyChanged <Item>(System.Windows.Controls.DataGrid dataGrid,
                                                              System.Collections.ObjectModel.ObservableCollection <Item> items,
                                                              Item item,
                                                              string propertyName,
                                                              ItemUpdatedPredicate updatePredicate,
                                                              ItemInsertEmptyPredicate insertEmptyPredicate,
                                                              ItemRemovePredicate <Item> removePredicate,
                                                              ItemRemovedPredicate removedPredicate)
            where Item : VariableItem
        {
            int index = items.IndexOf(item);

            if (index < 0 || index >= dataGrid.Items.Count)
            {
                return;
            }

            if (propertyName == "Name")
            {
                if (item.Name == null || item.Name == "")
                {
                    if (index < dataGrid.Items.Count - 1)
                    {
                        removePredicate(item);

                        items.RemoveAt(index);

                        removedPredicate(index);

                        if (index > 0)
                        {
                            Util.SelectDataGridItem(dataGrid, index - 1);
                        }
                    }
                }
                else
                {
                    updatePredicate(index);

                    int next_index = index + 1;
                    // insert new empty row if needed
                    if (next_index == items.Count)
                    {
                        insertEmptyPredicate(next_index);
                    }
                    // select current row, move to next one is automatic
                    Util.SelectDataGridItem(dataGrid, index);
                }
            }
            else if (propertyName == "IsEnabled")
            {
                updatePredicate(index);
            }
        }
示例#2
0
 public static void DataGridItemPropertyChanged <Item>(System.Windows.Controls.DataGrid dataGrid,
                                                       System.Collections.ObjectModel.ObservableCollection <Item> items,
                                                       Item item,
                                                       string propertyName,
                                                       ItemUpdatedPredicate updatePredicate,
                                                       ItemInsertEmptyPredicate insertEmptyPredicate)
     where Item : VariableItem
 {
     DataGridItemPropertyChanged(dataGrid, items, item, propertyName,
                                 updatePredicate,
                                 insertEmptyPredicate,
                                 delegate(Item it) { },
                                 delegate(int index) { });
 }