예제 #1
0
 private void ChangeOneStateInvoke(int line, bool bo, bool IsMaxLine)
 {
     try
     {
         DataGridDelegate DGD = new DataGridDelegate(ChangeOneState);
         DGD(line, bo, IsMaxLine);
     }
     catch (Exception ex)
     {
         this.AddMessageError("出现异常" + ex.ToString());
     }
 }
        public virtual void EditFirstCell(DataGridEditAction cellEditAction,
                                          DataGridEditAction?rowEditAction,
                                          DataGridDelegate subscribeToEvent,
                                          DataGridCellValidateDelegate validateEvent,
                                          DataGridDelegate unsubscribeToEvent)
        {
            // The first customer property should always be a string
            if (properties[0].PropertyType == typeof(string))
            {
                DataGrid dataGrid = new DataGrid();
                string   originalValue;
                string   updatedValue;
                dataGrid.ItemsSource = null;
                dataGrid.SelectedItems.Clear();
                rowLoaded            = false;
                dataGridRow          = null;
                isLoaded             = false;
                dataGrid.Loaded     += new RoutedEventHandler(dataGrid_Loaded);
                dataGrid.ColumnWidth = new DataGridLength(50);
                dataGrid.Width       = 650;
                dataGrid.Height      = 250;
                CustomerList customerList = new CustomerList(1);
                customerList[0].LastName = "A";
                PagedCollectionView pagedCollectionView = new PagedCollectionView(customerList);
                pagedCollectionView.SortDescriptions.Add(new System.ComponentModel.SortDescription("LastName", System.ComponentModel.ListSortDirection.Ascending));

                TestPanel.Children.Add(dataGrid);
                EnqueueConditional(delegate { return(isLoaded); });
                this.EnqueueYieldThread();
                EnqueueCallback(delegate
                {
                    dataGrid.LoadingRow += new EventHandler <DataGridRowEventArgs>(dataGrid_LoadingRowGetRow);
                    subscribeToEvent(dataGrid);

                    dataGrid.ItemsSource = pagedCollectionView;
                });
                EnqueueConditional(delegate { return(rowLoaded); });

                this.EnqueueYieldThread();
                EnqueueCallback(delegate
                {
                    dataGrid.LoadingRow -= new EventHandler <DataGridRowEventArgs>(dataGrid_LoadingRowGetRow);

                    bool success = dataGrid.BeginEdit();
                    Assert.IsTrue(success, "BeginEdit was not successful");
                });
                this.EnqueueYieldThread();
                //}
                EnqueueCallback(delegate
                {
                    //Set column to valid value
                    Assert.IsTrue(dataGrid.Columns[0].GetCellContent(customerList[0]) is TextBox, "Not a TextBox");
                    TextBox cell  = ((TextBox)dataGrid.CurrentColumn.GetCellContent(customerList[0]));
                    originalValue = cell.Text;
                    ((TextBox)dataGrid.CurrentColumn.GetCellContent(customerList[0])).Text = Common.RandomString(10);
                    updatedValue = cell.Text;

                    // Either commit or cancel the cell edit
                    if (cellEditAction == DataGridEditAction.Commit)
                    {
                        dataGrid.CommitEdit(DataGridEditingUnit.Cell, true /*exitEditing*/);
                    }
                    else
                    {
                        dataGrid.CancelEdit(DataGridEditingUnit.Cell);
                    }

                    // Either commit or cancel the row edit
                    if (rowEditAction == DataGridEditAction.Commit)
                    {
                        dataGrid.CommitEdit(DataGridEditingUnit.Row, true /*exitEditing*/);
                    }
                    else if (rowEditAction == DataGridEditAction.Cancel)
                    {
                        dataGrid.CancelEdit(DataGridEditingUnit.Row);
                    }

                    updatedValue = properties[0].GetValue(customerList[0], null) as String;
                    validateEvent(dataGrid, originalValue, updatedValue);
                    unsubscribeToEvent(dataGrid);
                });
            }
        }