예제 #1
0
파일: Form1.cs 프로젝트: pengmin/JCWX
        private void ReadXmlToList(string s_menufilepath)
        {
            XDocument doc = XDocument.Load(s_menufilepath);
            var elements = doc.Element("NewDataSet").Elements();
            if (elements.Any())
            {
                foreach (var e in elements)
                {
                    var row = new DataGridRow();
                    if (e.Element("Id") != null)
                    {
                        row.Id = e.Element("Id").Value;
                        if (e.Element("Title") != null)
                            row.Title = e.Element("Title").Value;
                        if (e.Element("Key") != null)
                            row.Key = e.Element("Key").Value;
                        if (e.Element("RootId") != null)
                            row.RootId = e.Element("RootId").Value;
                        if (e.Element("Url") != null)
                            row.Url = e.Element("Url").Value;

                        if (e.Element("MenuType") != null)
                            row.MenuType = e.Element("MenuType").Value;

                        Rows.Add(row);
                    }
                }
            }
        }
        public override DataGridRow GetPreviousVisibleRow(DataGridRow currentRow)
        {
            DataGridRow previousRow = base.GetPreviousVisibleRow(currentRow);

            if (previousRow == null)
            {
                var dataGrid = currentRow.DataGrid;
                return (dataGrid.Tag as DataGridRow);
            }
            else
            {
                if (previousRow.DetailsVisibility == Visibility.Visible)
                {
                    while (true)
                    {
                        var nestedGrid = GetNestedGrid(previousRow);
                        if (nestedGrid != null &&
                            nestedGrid.Rows.GetFirstVisibleRow() != null &&
                            nestedGrid.Columns.GetFirstVisibleColumn() != null)
                        {
                            previousRow = GetBottomVisibleRow(nestedGrid);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                return previousRow;
            }
        }
 public DataGridCellEditingCancelEventArgs(DataGridColumnBase dataGridColumn, 
                                           DataGridRow dataGridRow,
                                           FrameworkElement element,
                                           DataGridEditingTriggerInfo editingTriggerInfo) : base(dataGridColumn, dataGridRow, element) 
 {
     this.EditingTriggerInfo = editingTriggerInfo;
 } 
예제 #4
0
 public DataGridRowEventArgs(DataGridRow dataGridRow) 
 {
     if (dataGridRow == null)
     { 
         throw new ArgumentNullException("dataGridRow");
     }
     this.Row = dataGridRow; 
 } 
예제 #5
0
 public DataGridBeginningEditEventArgs(DataGridColumn column,
                                       DataGridRow row,
                                       RoutedEventArgs editingEventArgs)
 {
     this.Column = column;
     this.Row = row;
     this.EditingEventArgs = editingEventArgs;
 }
예제 #6
0
 public override void BindCellContent(FrameworkElement cellContent, DataGridRow row)
 {
     C1CheckeredBorder border = (C1CheckeredBorder)cellContent;
     Binding binding = CopyBinding(Binding);
     binding.Converter = new ColorConverter();
     binding.Source = row.DataItem;
     border.Style = CellContentStyle;
     border.SetBinding(System.Windows.Controls.Control.BackgroundProperty, binding);
 }
예제 #7
0
 public DataGridEndingEditEventArgs(DataGridColumn column,
                                    DataGridRow row,
                                    FrameworkElement editingElement,
                                    DataGridEditingUnit editingUnit)
 {
     this.Column = column;
     this.Row = row;
     this.EditingElement = editingElement;
     this.EditingUnit = editingUnit;
 }
 public C1DataGrid GetNestedGrid(DataGridRow row)
 {
     if ((row.Type == DataGridRowType.Item ||
            row.Type == DataGridRowType.New) &&
        row.DetailsVisibility == Visibility.Visible)
     {
         return row.DetailsPresenter.Content as C1DataGrid;
     }
     return null;
 }
예제 #9
0
 public override FrameworkElement CreateCellContent(DataGridRow row)
 {
     C1CheckeredBorder border = new C1CheckeredBorder();
     border.BorderBrush = DataGrid.BorderBrush;
     border.BorderThickness = new Thickness(1);
     border.Margin = new Thickness(1);
     border.CornerRadius = new CornerRadius(2);
     border.SquareWidth = 7;
     return border;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Windows.Controls.DataGridPreparingCellForEditEventArgs" /> class.
 /// </summary>
 /// <param name="column">The column that contains the cell to be edited.</param>
 /// <param name="row">The row that contains the cell to be edited.</param>
 /// <param name="editingEventArgs">Information about the user gesture that caused the cell to enter edit mode.</param>
 /// <param name="editingElement">The element that the column displays for a cell in editing mode.</param>
 public DataGridPreparingCellForEditEventArgs(DataGridColumn column, 
                                              DataGridRow row, 
                                              RoutedEventArgs editingEventArgs,
                                              FrameworkElement editingElement)
 {
     this.Column = column;
     this.Row = row;
     this.EditingEventArgs = editingEventArgs;
     this.EditingElement = editingElement;
 }
예제 #11
0
        /// <summary>
        /// AutomationPeer for DataGridRow
        /// </summary>
        /// <param name="owner">DataGridRow</param>
        public DataGridRowAutomationPeer(DataGridRow owner)
            : base(owner)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            UpdateEventSource();
        }
예제 #12
0
        public void DetailsTemplate()
        {
            Type propertyType = typeof(DataTemplate);
            bool expectGet = true;
            bool expectSet = true;
            bool hasSideEffects = true;

            DataGridRow control = new DataGridRow();
            Assert.IsNotNull(control);

            // Verify Dependency Property Property member
            FieldInfo fieldInfo = typeof(DataGridRow).GetField("DetailsTemplateProperty", BindingFlags.Static | BindingFlags.Public);
            Assert.AreEqual(typeof(DependencyProperty), fieldInfo.FieldType, "DataGridRow.DetailsTemplateProperty not expected type 'DependencyProperty'.");

            // Verify Dependency Property Property's value type
            DependencyProperty property = fieldInfo.GetValue(null) as DependencyProperty;

            Assert.IsNotNull(property);

            // 


            // Verify Dependency Property CLR property member
            PropertyInfo propertyInfo = typeof(DataGridRow).GetProperty("DetailsTemplate", BindingFlags.Instance | BindingFlags.Public);
            Assert.IsNotNull(propertyInfo, "Expected CLR property DataGridRow.DetailsTemplate does not exist.");
            Assert.AreEqual(propertyType, propertyInfo.PropertyType, "DataGridRow.DetailsTemplate not expected type 'DataTemplate'.");

            // Verify getter/setter access
            Assert.AreEqual(expectGet, propertyInfo.CanRead, "Unexpected value for propertyInfo.CanRead.");
            Assert.AreEqual(expectSet, propertyInfo.CanWrite, "Unexpected value for propertyInfo.CanWrite.");

            // Verify that we set what we get
            if (expectSet) // if expectSet == false, this block can be removed
            {
                DataTemplate template = new DataTemplate();

                control.DetailsTemplate = template;

                Assert.AreEqual(template, control.DetailsTemplate);
            }

            // Verify Dependency Property callback
            if (hasSideEffects)
            {
                MethodInfo methodInfo = typeof(DataGridRow).GetMethod("OnDetailsTemplatePropertyChanged", BindingFlags.Static | BindingFlags.NonPublic);
                Assert.IsNotNull(methodInfo, "Expected DataGridRow.DetailsTemplate to have static, non-public side-effect callback 'OnDetailsTemplatePropertyChanged'.");

                // 
            }
            else
            {
                MethodInfo methodInfo = typeof(DataGridRow).GetMethod("OnDetailsTemplatePropertyChanged", BindingFlags.Static | BindingFlags.NonPublic);
                Assert.IsNull(methodInfo, "Expected DataGridRow.DetailsTemplate NOT to have static side-effect callback 'OnDetailsTemplatePropertyChanged'.");
            }
        }
예제 #13
0
파일: MenuForm.cs 프로젝트: yajunsun/JCWX
 public MenuForm(IEnumerable<DataGridRow> parentRows, DataGridRow row)
     : this(parentRows)
 {
     if (row.MenuType == "Click")
         radioButton2.Checked = true;
     else
         radioButton1.Checked = true;
     if (!String.IsNullOrEmpty(row.RootId))
         comboBox1.SelectedValue = row.RootId;
     textBox1.Text = row.Title;
     textBox2.Text = row.Key;
     textBox3.Text = row.Url;
     RowId = row.Id;
 }
예제 #14
0
        public DataGridDataErrorEventArgs(Exception exception, 
                                          DataGridColumnBase dataGridColumn, 
                                          DataGridRow dataGridRow)
        { 
            if (dataGridColumn == null)
            {
                throw new ArgumentNullException("dataGridColumn"); 
            }
            //
 
 

 

            this.Column = dataGridColumn;
            this.Row = dataGridRow; 
            this.Exception = exception;
        }
 public override FrameworkElement GetCellEditingContent(DataGridRow row)
 {
     var txt = new C1MaskedTextBox();
     txt.Mask = Mask;
     txt.TextMaskFormat = TextMaskFormat;
     txt.TextWrapping = TextWrapping;
     txt.Padding = new Thickness(0);
     if (Binding != null)
     {
         txt.SetBinding(C1MaskedTextBox.ValueProperty, CopyBinding(Binding));
     }
     txt.TextAlignment = HorizontalAlignment == HorizontalAlignment.Left ? TextAlignment.Left : HorizontalAlignment == HorizontalAlignment.Right ? TextAlignment.Right : TextAlignment.Center;
     txt.VerticalContentAlignment = VerticalAlignment;
     if (CellEditingContentStyle != null && txt.Style == null)
     {
         txt.Style = CellEditingContentStyle;
     }
     return txt;
 }
 public override FrameworkElement GetCellEditingContent(DataGridRow row)
 {
     var textBox = (C1TextBoxBase)base.GetCellEditingContent(row);
     textBox.KeyDown += (s, e) =>
         {
             if (e.Key == System.Windows.Input.Key.Enter)
             {
                 string newText = textBox.Text;
                 var selectionStart = textBox.SelectionStart;
                 newText = newText.Remove(selectionStart, textBox.SelectionLength);
                 newText = newText.Insert(selectionStart, "\n");
                 textBox.Text = newText;
                 textBox.Select(selectionStart + 1, 0);
                 e.Handled = true;
                 row.Presenter.InvalidateMeasure();
             }
         };
     return textBox;
 }
 public override DataGridRow GetNextVisibleRow(DataGridRow currentRow)
 {
     if (currentRow.DetailsVisibility == Visibility.Visible)
     {
         var nestedGrid = GetNestedGrid(currentRow);
         if (nestedGrid != null && nestedGrid.Rows.GetFirstVisibleRow() != null && nestedGrid.Columns.GetFirstVisibleColumn() != null)
         {
             return GetTopVisibleRow(nestedGrid);
         }
     }
     var nextRow = base.GetNextVisibleRow(currentRow);
     if (nextRow != null)
     {
         return nextRow;
     }
     else
     {
         var dataGrid = currentRow.DataGrid;
         while (true)
         {
             var parentRow = GetParentRow(dataGrid);
             if (parentRow != null)
             {
                 dataGrid = parentRow.DataGrid;
                 nextRow = base.GetNextVisibleRow(parentRow);
                 if (nextRow != null)
                 {
                     break;
                 }
             }
             else
             {
                 break;
             }
         }
         return nextRow;
     }
 }
예제 #18
0
    public static DataGridCell GetCell(DataGrid dataGrid, int row, int column)
    {
        DataGridRow rowContainer = GetRow(dataGrid, row);

        if (rowContainer != null)
        {
            DataGridCellsPresenter presenter = GetVisualChild <DataGridCellsPresenter>(rowContainer);
            if (presenter == null)
            {
                dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                presenter = GetVisualChild <DataGridCellsPresenter>(rowContainer);
            }
            // try to get the cell but it may possibly be virtualized
            DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
            if (cell == null)
            {
                // now try to bring into view and retreive the cell
                dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
            }
            return(cell);
        }
        return(null);
    }
예제 #19
0
        /*
         * static public DataGridCell GetCell(DataGrid dg, int row, int column)
         * {
         *  DataGridRow rowContainer = GetRow(dg, row);
         *
         *  if (rowContainer != null)
         *  {
         *      DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
         *
         *      // try to get the cell but it may possibly be virtualized
         *      DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
         *      if (cell == null)
         *      {
         *          // now try to bring into view and retreive the cell
         *          dg.ScrollIntoView(rowContainer, dg.Columns[column]);
         *          cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
         *      }
         *      return cell;
         *  }
         *  return null;
         * }
         *
         * static public DataGridRow GetRow(DataGrid dg, int index)
         * {
         *  DataGridRow row = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(index);
         *  if (row == null)
         *  {
         *      // may be virtualized, bring into view and try again
         *      dg.ScrollIntoView(dg.Items[index]);
         *      row = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(index);
         *  }
         *  return row;
         * }
         *
         * static T GetVisualChild<T>(Visual parent) where T : Visual
         * {
         *  T child = default(T);
         *  int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
         *  for (int i = 0; i < numVisuals; i++)
         *  {
         *      Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
         *      child = v as T;
         *      if (child == null)
         *      {
         *          child = GetVisualChild<T>(v);
         *      }
         *      if (child != null)
         *      {
         *          break;
         *      }
         *  }
         *  return child;
         * }
         *
         */


        public static DataGridCell GetCell(DataGrid dataGrid, int row, int column)
        {
            DataGridRow rowContainer = dataGrid.ItemContainerGenerator.ContainerFromIndex(row) as DataGridRow;

            if (rowContainer == null)
            {
                dataGrid.UpdateLayout();
                dataGrid.ScrollIntoView(dataGrid.Items[row]);
                rowContainer = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(row);
            }
            if (rowContainer != null)
            {
                DataGridCellsPresenter presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer);
                if (presenter == null)
                {
                    /* if the row has been virtualized away, call its ApplyTemplate() method
                     * to build its visual tree in order for the DataGridCellsPresenter
                     * and the DataGridCells to be created */
                    rowContainer.ApplyTemplate();
                    presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer);
                }
                if (presenter != null)
                {
                    DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                    if (cell == null)
                    {
                        /* bring the column into view
                         * in case it has been virtualized away */
                        dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                        cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                    }
                    return(cell);
                }
            }
            return(null);
        }
예제 #20
0
        private void MenuItem_Reset_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Get the clicked MenuItem
                var menuItem = (MenuItem)sender;

                //Get the ContextMenu to which the menuItem belongs
                var contextMenu = (ContextMenu)menuItem.Parent;

                //Find the placementTarget
                var item = (DataGrid)contextMenu.PlacementTarget;

                DataGridRow dgr = (DataGridRow)item.ItemContainerGenerator.ContainerFromIndex(item.SelectedIndex);

                string Remark = ((DataRowView)dgr.Item).Row.Field <string>("Remark").ToString();

                Dispatcher.BeginInvoke(new ThreadStart(() => UpdateWebsiteMaxViweres(Remark)));
            }
            catch (Exception ex)
            {
                clsLogger.WriteToLogFile("Error during reseting max count on menu click :" + ex.Message);
            }
        }
예제 #21
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            ArrayList selectIds = new ArrayList();

            for (int i = 0; i < this.HrvDataGrid.Items.Count; i++)
            {
                var         cntr   = HrvDataGrid.ItemContainerGenerator.ContainerFromIndex(i);
                DataGridRow ObjROw = (DataGridRow)cntr;
                if (ObjROw != null)
                {
                    FrameworkElement objElement = HrvDataGrid.Columns[0].GetCellContent(ObjROw);
                    if (objElement != null)
                    {
                        System.Windows.Controls.CheckBox objChk = (System.Windows.Controls.CheckBox)objElement;
                        if (objChk.IsChecked == true)
                        {
                            selectIds.Add(((HRVRecordData)ObjROw.Item).Id);
                        }
                    }
                }
            }

            if (selectIds.Count > 0)
            {
                if (PmtsMessageBox.CustomControl1.Show("确定要删除选择?") == PmtsMessageBox.ServerMessageBoxResult.OK)
                {
                    hrvdb.DeleteHrvData(selectIds);
                    refreshHistory(selectIds);
                    OnDataOrPageChanged(_nowPage, _num);
                }
            }
            else
            {
                PmtsMessageBox.CustomControl1.Show("请先选中一条数据!");
            }
        }
        /// <summary>
        /// 指定した行、列のセルを取得
        /// </summary>
        /// <param name="grid">取得対象DataGrid</param>
        /// <param name="row">行</param>
        /// <param name="column">列番号</param>
        /// <returns>セル</returns>
        private static DataGridCell?GetCell(DataGrid grid, DataGridRow row, int column)
        {
            if (row != null)
            {
                var presenter = FindVisualChild <DataGridCellsPresenter>(row);
                if (presenter == null)
                {
                    row.ApplyTemplate();
                    presenter = FindVisualChild <DataGridCellsPresenter>(row);
                }
                if (presenter != null)
                {
                    var cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                    if (cell != null)
                    {
                        grid.ScrollIntoView(row, grid.Columns[column]);
                        cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as DataGridCell;
                    }
                    return(cell);
                }
            }

            return(null);
        }
예제 #23
0
        private void DataGridRow_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row      = sender as DataGridRow;
            Playlist    playlist = row.DataContext as Playlist;


            if (MessageBox.Show(playlist.mName + "을 삭제 하시겠습니까?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
            {
                return;
            }
            else
            {
                mw.mAccount.mPlaylistList.Remove(playlist);
                dgPlaylist.Items.Refresh();
                foreach (TreeViewItem item in mw.tviPlaylist.Items)
                {
                    if (item.Header.ToString() == playlist.mName)
                    {
                        mw.tviPlaylist.Items.Remove(item);
                        break;
                    }
                }
            }
        }
예제 #24
0
 private void DataGridRow_PreviewMouseButtonDown(object sender, MouseButtonEventArgs e)
 {
     if (isAdmin)
     {
         DataGridRow      row   = (DataGridRow)sender;
         DataRowView      rw    = (DataRowView)row.Item;
         MessageBoxResult resul = MessageBox.Show("Вы уверены, что хотите удалить сеанс?", "Удаление", MessageBoxButton.OKCancel);
         if (resul != MessageBoxResult.Cancel)
         {
             cn.Open();
             int result = Connection.DeleteSession(Convert.ToInt32(rw.Row.ItemArray[0].ToString()), cn);
             if (result == 1)
             {
                 MessageBox.Show("Удаление прошло успешно!");
             }
             else
             {
                 MessageBox.Show("Ошибка удаления!");
             }
             cn.Close();
             FillSessions();
         }
     }
 }
예제 #25
0
        public static DataGridCell GetCell(DataGrid dataGrid, int rowIndex, int columnIndex)
        {
            DataGridCell cell = null;

            if (rowIndex > -1 && columnIndex > -1)
            {
                DataGridRow rowContainer = GetRow(dataGrid, rowIndex);
                if (rowContainer != null)
                {
                    DataGridCellsPresenter presenter = GetVisualChild <DataGridCellsPresenter>(rowContainer);
                    if (null != presenter)
                    {
                        cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
                        if (cell == null)
                        {
                            dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[columnIndex]);
                            cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(columnIndex);
                        }
                    }
                }
            }

            return(cell);
        }
예제 #26
0
        public static int GetDataGridClickedRowNum(MouseEventArgs e)
        {
            DependencyObject dep = GedDataGridClickedDependencyObj(e);

            int k = -1;

            if (dep is DataGridCell)
            {
                DataGridCell cell = dep as DataGridCell;

                // navigate further up the tree
                while ((dep != null) && !(dep is DataGridRow))
                {
                    dep = VisualTreeHelper.GetParent(dep);
                }

                DataGridRow row = dep as DataGridRow;


                k = FindDataGridRowIndex(row);
            }

            return(k);
        }
예제 #27
0
        private void DeckCardMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (sender == null)
            {
                return;
            }
            var ansc = FindAncestor <Expander>((FrameworkElement)sender);

            if (ansc == null)
            {
                return;
            }

            activeRow   = FindAncestor <DataGridRow>((DependencyObject)e.OriginalSource);
            dragSection = (ObservableSection)ansc.DataContext;
            if (activeRow != null)
            {
                int cardIndex = activeRow.GetIndex();
                var getCard   = dragSection.Cards.ElementAt(cardIndex);
                CardSelected(sender, new SearchCardImageEventArgs {
                    SetId = getCard.SetId, Image = getCard.ImageUri, CardId = getCard.Id, Alternate = ""
                });
            }
        }
예제 #28
0
        private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            // Some operations with this row
            GameDetailView gdv = new GameDetailView();
            DataGridRow    row = sender as DataGridRow;
            MainWindow     mw  = this.TryFindParent <MetroWindow>() as MainWindow;

            try
            {
                MatchReferenceBinding dcMrb = (MatchReferenceBinding)row.DataContext;
                gdv = GameDetailViewInit(dcMrb);
                mw.GameDetailChildWindow.Content = gdv;
            }
            catch (Exception ex)
            {
                ((GameDetailViewModel)gdv.DataContext).ErrorMessage = ex.Message;
            }
            finally
            {
                mw.LoLDataRefresh.IsEnabled     = false;
                mw.LoLSummonerLogin.IsEnabled   = false;
                mw.GameDetailChildWindow.IsOpen = true;
            }
        }
예제 #29
0
        private void songSet_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataGrid songSet = sender as DataGrid;

            if (e.AddedItems != null && e.AddedItems.Count > 0)
            {
                // find row for the first selected item
                DataGridRow row = (DataGridRow)songSet.ItemContainerGenerator.ContainerFromItem(e.AddedItems[0]);
                if (row != null)
                {
                    DataGridCellsPresenter presenter = GetVisualChild <DataGridCellsPresenter>(row);
                    // find grid cell object for the cell with index 0
                    DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(0) as DataGridCell;
                    if (cell != null)
                    {
                        defaultSongUrl = (((TextBlock)cell.Content).Text);
                    }
                }

                txtBox_songUrl.Text = defaultSongUrl;

                Trace.WriteLine("NEXT SONG: " + defaultSongUrl);
            }
        }
예제 #30
0
 private void PickUpCard(object sender, MouseEventArgs e)
 {
     if (MouseButtonState.Pressed.Equals(e.LeftButton) && dragActive)
     {
         DataGridRow SearchCard = new DataGridRow();
         var         row        = (DataRowView)resultsGrid.SelectedItem;
         if (row == null)
         {
             return;
         }
         if (CardAdded == null)
         {
             return;
         }
         var rowid = row["id"] as string;
         if (rowid != null)
         {
             DataNew.Entities.MultiCard getCard = Game.GetCardById(Guid.Parse(rowid)).ToMultiCard();
             DataObject dragCard = new DataObject("Card", getCard);
             DragDrop.DoDragDrop(SearchCard, dragCard, DragDropEffects.Copy);
         }
     }
     dragActive = false;
 }
예제 #31
0
        private void filterRows()
        {
            DataView defView = _dataTable.DefaultView;

            int count = defView.Count;

            for (int i = 0; i < count; i++)
            {
                DataRowView drv = defView[i];
                DataGridRow dgr = MainGrid.ItemContainerGenerator.ContainerFromItem(drv) as DataGridRow;
                if (dgr != null)
                {
                    bool contains = false;
                    for (int j = 1; j < _dataTable.Columns.Count; j++)
                    {
                        if (_dataTable.Columns[j].ColumnName == _idColumnName)
                        {
                            continue;
                        }
                        if (drv[j].ToString().ToUpper().Contains(textBox.Text.ToUpper()))
                        {
                            contains = true;
                            break;
                        }
                    }
                    if (contains)
                    {
                        dgr.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        dgr.Visibility = System.Windows.Visibility.Collapsed;
                    }
                }
            }
        }
예제 #32
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
            if (button == null)
            {
                return;
            }
            DataGridRow dgrow = FindItem.FindParentItem <DataGridRow>(button);

            if (dgrow == null)
            {
                return;
            }

            ReportsSetting reportsSetting = (ReportsSetting)dgrow.Item;

            if (reportsSetting == null)
            {
                return;
            }
            if (!reportsSetting.save())
            {
                System.Windows.MessageBox.Show("Не удалось сохранить настройку отчета. Подробности см. в логе ошибок!");
            }
            else
            {
                if (reportsSetting.NextDateCreated != null)
                {
                    System.Windows.MessageBox.Show("Настройка выгрузки сохранена.\nСледующая дата выгрузки " + ((DateTime)reportsSetting.NextDateCreated).ToString());
                }
                else
                {
                    System.Windows.MessageBox.Show("Настройка выгрузки сохранена.\nСледующая дата выгрузки - не установлено.");
                }
            }
        }
        void RbnSelected_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton radioButton = sender as RadioButton;

            if (radioButton == null)
            {
                return;
            }

            DataGridRow dgrow = FindItem.FindParentItem <DataGridRow>(radioButton);

            if (dgrow == null)
            {
                return;
            }

            Equipment equipment = (Equipment)dgrow.Item;

            if (equipment == null)
            {
                return;
            }
            equipment.IsSelected = true;
        }
예제 #34
0
        private void WordView_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            string                 inValue   = (e.EditingElement as TextBox).Text;
            string                 wordValue = ds.Tables[0].Rows[int.Parse((WordView.Columns[0].GetCellContent(WordView.SelectedItem) as TextBlock).Text) - 1][1].ToString();
            int                    Crr       = int.Parse(txtCrrBlk.Text);
            int                    Err       = int.Parse(txtErrBlk.Text);
            DataRowView            drv       = WordView.SelectedItem as DataRowView;
            DataGridRow            row       = (DataGridRow)this.WordView.ItemContainerGenerator.ContainerFromIndex(WordView.SelectedIndex);
            DataGridCellsPresenter presenter = GetVisualChild <DataGridCellsPresenter>(row);
            DataGridCell           cell      = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(4);
            DataGridTemplateColumn tempColum = this.WordView.Columns[1] as DataGridTemplateColumn;
            FrameworkElement       element   = this.WordView.Columns[1].GetCellContent(this.WordView.SelectedItem);

            if (inValue.ToUpper() == wordValue.ToUpper())
            {
                if ((Crr + Err) > WordView.SelectedIndex)
                {
                    Crr++;
                    Err--;
                }
                else
                {
                    Crr++;
                }
                cell.Foreground = new SolidColorBrush(Colors.Black);
                if (element != null)
                {
                    TextBlock txtBlock = tempColum.CellTemplate.FindName("txtBlk", element) as TextBlock;
                    MaterialDesignThemes.Wpf.PackIcon pIcon = tempColum.CellTemplate.FindName("PICON", element) as MaterialDesignThemes.Wpf.PackIcon;
                    pIcon.Foreground = new SolidColorBrush(Colors.Gray);
                }
            }
            else
            {
                if ((Crr + Err) > WordView.SelectedIndex)
                {
                    Crr--;
                    Err++;
                }
                else
                {
                    Err++;
                }
                cell.Foreground = new SolidColorBrush(Colors.Red);
                if (element != null)
                {
                    TextBlock txtBlock = tempColum.CellTemplate.FindName("txtBlk", element) as TextBlock;
                    MaterialDesignThemes.Wpf.PackIcon pIcon = tempColum.CellTemplate.FindName("PICON", element) as MaterialDesignThemes.Wpf.PackIcon;
                    pIcon.Foreground = new SolidColorBrush(Colors.Red);
                    txtBlock.Text    = (int.Parse(txtBlock.Text) + 1).ToString();
                }
            }
            //for(int i=0;i<=WordView.Items.Count-1;i++)
            //{
            //    if(i==WordView.SelectedIndex)
            //    {
            //        inValue = (e.EditingElement as TextBox).Text;
            //    }
            //    else
            //    {
            //        inValue = ds.Tables[0].Rows[i][5].ToString(); //   (WordView.Columns[3].GetCellContent(WordView.Items[i]) as TextBlock).Text;
            //    }
            //    wordValue = ds.Tables[0].Rows[i][1].ToString();
            //    if (inValue != "")
            //    {
            //        if (inValue == wordValue)
            //        {
            //            Crr += 1;
            //        }
            //        else
            //        {
            //            Err += 1;
            //        }
            //    }
            //}
            txtCrrBlk.Text = Crr.ToString();
            txtErrBlk.Text = Err.ToString();
        }
예제 #35
0
        public static System.Windows.Controls.DataGridCell GetCell(this System.Windows.Controls.DataGrid grid, DataGridRow row, int column)
        {
            if (row != null)
            {
                DataGridCellsPresenter presenter = Converters.HelperClass.GetVisualChild <DataGridCellsPresenter>(row);

                if (presenter == null)
                {
                    grid.ScrollIntoView(row, grid.Columns[column]);
                    presenter = Converters.HelperClass.GetVisualChild <DataGridCellsPresenter>(row);
                }

                System.Windows.Controls.DataGridCell cell = (System.Windows.Controls.DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
                return(cell);
            }
            return(null);
        }
예제 #36
0
        private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            // execute some code
            DataGridRow      r  = (DataGridRow)sender;
            dynamic          i  = r.Item;
            FHXCompareResult rs = i.Value;

            var diffBuilder = new SideBySideDiffBuilder(new Differ());

            if (rs.NewValue == null)
            {
                this.tbOld.Document.Blocks.Clear();
                this.tbNew.Document.Blocks.Clear();

                var p  = new Paragraph();
                var tr = new TextRange(p.ContentStart, p.ContentEnd);
                tr.Text = rs.OldValue;

                this.tbOld.Document.Blocks.Add(p);
            }
            else
            {
                var diff = diffBuilder.BuildDiffModel(rs.OldValue, rs.NewValue);

                RichTextBox[] tb = new RichTextBox[2] {
                    this.tbOld, this.tbNew
                };
                List <DiffPiece>[] t = new List <DiffPiece>[2] {
                    diff.OldText.Lines, diff.NewText.Lines
                };

                for (int j = 0; j < 2; j++)
                {
                    tb[j].Document.Blocks.Clear();
                    foreach (DiffPiece line in t[j])
                    {
                        var p = new Paragraph();
                        p.Margin = new Thickness(0);
                        TextRange tr;
                        tr = new TextRange(p.ContentStart, p.ContentEnd);
                        switch (line.Type)
                        {
                        case ChangeType.Inserted:
                            tr.Text = line.Text;
                            tr.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.LightGreen);
                            break;

                        case ChangeType.Deleted:
                            tr.Text = line.Text;
                            tr.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.LightPink);
                            break;

                        case ChangeType.Modified:
                            tr.Text = line.Text;
                            tr.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Goldenrod);
                            break;

                        case ChangeType.Imaginary:
                            tr.Text = "            ";
                            tr.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Gray);
                            break;

                        case ChangeType.Unchanged:
                            tr.Text = line.Text;
                            tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Black);
                            break;

                        default:
                            tr.Text = line.Text;
                            tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);
                            break;
                        }
                        tb[j].Document.Blocks.Add(p);
                    }
                }
            }
        }
        /// <summary>
        ///     Prepares a cell for use.
        /// </summary>
        /// <remarks>
        ///     Updates the column reference.
        /// </remarks>
        internal void PrepareCell(object item, DataGridRow ownerRow, int index)
        {
            Debug.Assert(_owner == null || _owner == ownerRow, "_owner should be null before PrepareCell is called or the same value as the ownerRow.");

            _owner = ownerRow;

            DataGrid dataGrid = _owner.DataGridOwner;
            if (dataGrid != null)
            {
                // The index of the container should correspond to the index of the column
                if ((index >= 0) && (index < dataGrid.Columns.Count))
                {
                    // Retrieve the column definition and pass it to the cell container
                    DataGridColumn column = dataGrid.Columns[index];
                    Column = column;
                    TabIndex = column.DisplayIndex;
                }

                if (IsEditing)
                {
                    // If IsEditing was left on and this container was recycled, reset it here.
                    // Setting this property will result in BuildVisualTree being called.
                    IsEditing = false;
                }
                else if ((Content as FrameworkElement) == null)
                {
                    // If there isn't already a visual tree, then create one.
                    BuildVisualTree();

                    if (!NeedsVisualTree)
                    {
                        Content = item;
                    }
                }

                // Update cell Selection
                bool isSelected = dataGrid.SelectedCellsInternal.Contains(this);
                SyncIsSelected(isSelected);
            }

            DataGridHelper.TransferProperty(this, StyleProperty);
            DataGridHelper.TransferProperty(this, IsReadOnlyProperty);
            CoerceValue(ClipProperty);
        }
예제 #38
0
        private void SourceField_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var comboBox = sender as ComboBox;

            if (this._skipSelectionChanged || comboBox.IsLoaded == false)
            {
                return;
            }
            bool doSave = false;

            if (((ComboBox)sender).IsLoaded && (e.AddedItems.Count > 0 || e.RemovedItems.Count > 0) && FieldGrid.SelectedIndex != -1)
            {     // disregard SelectionChangedEvent fired on population from binding
                for (Visual visual = (Visual)sender; visual != null; visual = (Visual)VisualTreeHelper.GetParent(visual))
                { // Traverse tree to find correct selected item
                    if (visual is DataGridRow)
                    {
                        DataGridRow           row = visual as DataGridRow;
                        object                val = row.Item;
                        System.Xml.XmlElement xml = val as System.Xml.XmlElement;
                        if (xml != null)
                        {
                            try
                            {
                                string nm      = xml.GetElementsByTagName("TargetName")[0].InnerText;
                                string xmlname = "";
                                try
                                {
                                    xmlname = _xml.SelectSingleNode("//Field[position()=" + (_selectedRowNum + 1).ToString() + "]/TargetName").InnerText;
                                }
                                catch { }
                                if (nm == xmlname)
                                {
                                    doSave = true;
                                    break;
                                }
                            }
                            catch { }
                        }
                    }
                }
            }

            int fieldnum = FieldGrid.SelectedIndex + 1;
            var nodes    = getFieldNodes(fieldnum);

            if (nodes != null && comboBox != null && comboBox.SelectedValue != null && doSave == true)
            {
                try
                {
                    string selected = comboBox.SelectedValue.ToString();
                    this._skipSelectionChanged = true;
                    if (nodes.Count == 1)
                    {
                        // source field selection should change to Copy
                        var node      = nodes.Item(0).SelectSingleNode("Method");
                        var nodeField = nodes.Item(0).SelectSingleNode("SourceName");
                        if (selected == _noneField && comboMethod.SelectedIndex != 0)
                        {
                            node.InnerText            = "None";
                            nodeField.InnerText       = selected;
                            comboMethod.SelectedIndex = 0;
                            saveFieldGrid();
                        }
                        else if (selected != _noneField)
                        {
                            node.InnerText            = "Copy";
                            nodeField.InnerText       = selected;
                            comboMethod.SelectedIndex = 1;
                            saveFieldGrid();
                        }
                        _selectedRowNum            = fieldnum;
                        this._skipSelectionChanged = false;
                    }
                }
                catch
                { }
            }
        }
예제 #39
0
 public DataGridCellEditEndingEventArgs(DataGridColumn column, DataGridRow row, FrameworkElement editingElement, DataGridEditAction editAction)
 {
 }
예제 #40
0
        /// <summary>
        ///     Determines if a cell meets the criteria for being chosen. If it does, it
        ///     calculates its a "distance" that can be compared to other cells.
        /// </summary>
        /// <param name="distance">
        ///     A value that represents the distance between the mouse and the cell.
        ///     This is not necessarily an accurate pixel number in some cases.
        /// </param>
        /// <returns>
        ///     true if the cell can be a drag target. false otherwise.
        /// </returns>
        private static bool CalculateCellDistance(FrameworkElement cell, DataGridRow rowOwner, Panel itemsHost, Rect itemsHostBounds, bool isMouseInCorner, out double distance)
        {
            GeneralTransform transform = cell.TransformToAncestor(itemsHost);
            Rect cellBounds = new Rect(new Point(), cell.RenderSize);

            // Limit to only cells that are entirely visible
            if (itemsHostBounds.Contains(transform.TransformBounds(cellBounds)))
            {
                Point pt = Mouse.GetPosition(cell);
                if (isMouseInCorner)
                {
                    // When the mouse is in the corner, go by distance from center of the cell
                    Vector v = new Vector(pt.X - (cellBounds.Width * 0.5), pt.Y - (cellBounds.Height * 0.5));
                    distance = v.Length;
                    return true;
                }
                else
                {
                    Point rowPt = Mouse.GetPosition(rowOwner);
                    Rect rowBounds = new Rect(new Point(), rowOwner.RenderSize);

                    // The mouse should overlap a row or column
                    if ((pt.X >= cellBounds.Left) && (pt.X <= cellBounds.Right))
                    {
                        // The mouse is within a column
                        if ((rowPt.Y >= rowBounds.Top) && (rowPt.Y <= rowBounds.Bottom))
                        {
                            // Mouse is within the cell
                            distance = 0.0;
                        }
                        else
                        {
                            // Mouse is outside but is within a columns horizontal bounds
                            distance = Math.Abs(pt.Y - cellBounds.Top);
                        }

                        return true;
                    }
                    else if ((rowPt.Y >= rowBounds.Top) && (rowPt.Y <= rowBounds.Bottom))
                    {
                        // Mouse is outside but is within a row's vertical bounds
                        distance = Math.Abs(pt.X - cellBounds.Left);
                        return true;
                    }
                }
            }

            distance = Double.PositiveInfinity;
            return false;
        }
예제 #41
0
 /// <summary>
 /// Fades the specified row.
 /// </summary>
 /// <param name="row">DataGridRow</param>
 private void FadeRow(DataGridRow row)
 {
     row.Foreground = new SolidColorBrush(Colors.Silver);
     row.Background = new SolidColorBrush(Colors.WhiteSmoke);
 }
예제 #42
0
 internal void OnUnloadingRowDetailsWrapper(DataGridRow row)
 {
     if (row != null &&
         row.DetailsLoaded == true &&
         row.DetailsPresenter != null)
     {
         DataGridRowDetailsEventArgs e = new DataGridRowDetailsEventArgs(row, row.DetailsPresenter.DetailsElement);
         OnUnloadingRowDetails(e);
         row.DetailsLoaded = false;
     }
 }
예제 #43
0
        /// <summary>
        ///     There was general input on a row header that indicated that
        ///     selection should occur on the given row.
        /// </summary>
        /// <param name="row">The target row.</param>
        /// <param name="startDragging">Whether the input also indicated that dragging should start.</param>
        internal void HandleSelectionForRowHeaderAndDetailsInput(DataGridRow row, bool startDragging)
        {
            object rowItem = row.Item;

            // When not dragging, move focus to the first cell
            if (!_isDraggingSelection && (_columns.Count > 0))
            {
                if (!IsKeyboardFocusWithin)
                {
                    // In order for CurrentCell to move focus, the
                    // DataGrid needs to be focused.
                    Focus();
                }

                DataGridCellInfo currentCell = CurrentCell;
                if (currentCell.Item != rowItem)
                {
                    // Change the CurrentCell if the row is different
                    CurrentCell = new DataGridCellInfo(rowItem, ColumnFromDisplayIndex(0), this);
                }
                else
                {
                    if (_currentCellContainer != null && _currentCellContainer.IsEditing)
                    {
                        // End the pending edit even for the same row
                        EndEdit(CommitEditCommand, _currentCellContainer, DataGridEditingUnit.Cell, /* exitEditingMode = */ true);
                    }
                }
            }

            // Select a row when the mode is not None and the unit allows selecting rows
            if (CanSelectRows)
            {
                MakeFullRowSelection(rowItem, /* allowsExtendSelect = */ true, /* allowsMinimalSelect = */ true);

                if (startDragging)
                {
                    BeginRowDragging();
                }
            }
        }
예제 #44
0
 internal void OnLoadingRowDetailsWrapper(DataGridRow row)
 {
     if (row != null &&
         row.DetailsLoaded == false &&
         row.DetailsVisibility == Visibility.Visible &&
         row.DetailsPresenter != null)
     {
         DataGridRowDetailsEventArgs e = new DataGridRowDetailsEventArgs(row, row.DetailsPresenter.DetailsElement);
         OnLoadingRowDetails(e);
         row.DetailsLoaded = true;
     }
 }
예제 #45
0
파일: MenuForm.cs 프로젝트: yajunsun/JCWX
        private void button1_Click(object sender, EventArgs e)
        {
            if (!Verfiry())
                return;

            Row = new DataGridRow();
            Row.Id = RowId;
            Row.Title = textBox1.Text;
            Row.Key = textBox2.Text;
            Row.Url = textBox3.Text;
            if (comboBox1.SelectedValue != "0")
            {
                Row.RootId = comboBox1.SelectedValue.ToString();
            }

            if (radioButton1.Checked)
                Row.MenuType = "View";
            else
                Row.MenuType = "Click";

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
예제 #46
0
        public void Load(List <ReplayKeyPoint> replay)
        {
            if (replay == null || replay.Count == 0)
            {
                return;
            }
            var selectedKeypoint = DataGridKeyPoints.SelectedItem as TurnViewItem;

            DataGridKeyPoints.Items.Clear();
            Replay            = replay;
            _currentGameState = Replay.FirstOrDefault(r => r.Data.Any(x => x.HasTag(GAME_TAG.PLAYER_ID)));
            if (_currentGameState == null)
            {
                Logger.WriteLine("Error loading replay. No player entity found.");
                return;
            }
            _playerController   = PlayerEntity.GetTag(GAME_TAG.CONTROLLER);
            _opponentController = OpponentEntity.GetTag(GAME_TAG.CONTROLLER);
            var          currentTurn = -1;
            TurnViewItem tvi         = null;

            foreach (var kp in Replay)
            {
                var entity = kp.Data.FirstOrDefault(x => x.Id == kp.Id);
                if (entity == null || (string.IsNullOrEmpty(entity.CardId) && kp.Type != KeyPointType.Victory && kp.Type != KeyPointType.Defeat))
                {
                    continue;
                }
                if (kp.Type == KeyPointType.Summon && entity.GetTag(GAME_TAG.CARDTYPE) == (int)TAG_CARDTYPE.ENCHANTMENT)
                {
                    continue;
                }
                var turn = (kp.Turn + 1) / 2;
                if (turn == 1)
                {
                    if (!kp.Data.Any(x => x.HasTag(GAME_TAG.PLAYER_ID) && x.GetTag(GAME_TAG.RESOURCES) == 1))
                    {
                        turn = 0;
                    }
                }
                if (turn > currentTurn)
                {
                    currentTurn = turn;
                    if (tvi != null && tvi.IsTurnRow && tvi.Turn.HasValue && !_collapsedTurns.Contains(tvi.Turn.Value))
                    {
                        DataGridKeyPoints.Items.Remove(tvi);                         //remove empty turns
                    }
                    tvi = new TurnViewItem {
                        Turn = turn, IsCollapsed = _collapsedTurns.Contains(turn), ShowAll = _showAllTurns.Contains(turn)
                    };
                    DataGridKeyPoints.Items.Add(tvi);
                }
                if (!_showAllTurns.Contains(turn))
                {
                    switch (kp.Type)
                    {
                    case KeyPointType.Attack:
                        if (!Config.Instance.ReplayViewerShowAttack)
                        {
                            continue;
                        }
                        break;

                    case KeyPointType.Death:
                        if (!Config.Instance.ReplayViewerShowDeath)
                        {
                            continue;
                        }
                        break;

                    case KeyPointType.Mulligan:
                    case KeyPointType.DeckDiscard:
                    case KeyPointType.HandDiscard:
                        if (!Config.Instance.ReplayViewerShowDiscard)
                        {
                            continue;
                        }
                        break;

                    case KeyPointType.Draw:
                    case KeyPointType.Obtain:
                    case KeyPointType.PlayToDeck:
                    case KeyPointType.PlayToHand:
                        if (!Config.Instance.ReplayViewerShowDraw)
                        {
                            continue;
                        }
                        break;

                    case KeyPointType.HeroPower:
                        if (!Config.Instance.ReplayViewerShowHeroPower)
                        {
                            continue;
                        }
                        break;

                    case KeyPointType.SecretStolen:
                    case KeyPointType.SecretTriggered:
                        if (!Config.Instance.ReplayViewerShowSecret)
                        {
                            continue;
                        }
                        break;

                    case KeyPointType.Play:
                    case KeyPointType.PlaySpell:
                    case KeyPointType.SecretPlayed:
                        if (!Config.Instance.ReplayViewerShowPlay)
                        {
                            continue;
                        }
                        break;

                    case KeyPointType.Summon:
                        if (!Config.Instance.ReplayViewerShowSummon)
                        {
                            continue;
                        }
                        break;
                    }
                }
                if (_collapsedTurns.Contains(turn))
                {
                    continue;
                }
                tvi = new TurnViewItem();
                if (kp.Player == ActivePlayer.Player)
                {
                    tvi.PlayerAction         = kp.Type.ToString();
                    tvi.AdditionalInfoPlayer = kp.GetAdditionalInfo();
                }
                else
                {
                    tvi.OpponentAction         = kp.Type.ToString();
                    tvi.AdditionalInfoOpponent = kp.GetAdditionalInfo();
                }
                tvi.KeyPoint = kp;
                DataGridKeyPoints.Items.Add(tvi);
            }
            if (selectedKeypoint != null)
            {
                var newSelection = selectedKeypoint.Turn.HasValue
                                                           ? DataGridKeyPoints.Items.Cast <TurnViewItem>()
                                   .FirstOrDefault(x => x.Turn.HasValue && x.Turn.Value == selectedKeypoint.Turn.Value)
                                                           : DataGridKeyPoints.Items.Cast <TurnViewItem>().FirstOrDefault(x => x.KeyPoint == selectedKeypoint.KeyPoint);
                if (newSelection != null)
                {
                    DataGridKeyPoints.SelectedItem = newSelection;
                    DataGridKeyPoints.ScrollIntoView(newSelection);
                    var         index = DataGridKeyPoints.Items.IndexOf(newSelection);
                    DataGridRow dgrow = (DataGridRow)DataGridKeyPoints.ItemContainerGenerator.ContainerFromItem(DataGridKeyPoints.Items[index]);
                    dgrow.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
                }
            }
            DataContext = this;
        }
예제 #47
0
        /// <summary>
        /// Restores the specified row to its defalt style.
        /// </summary>
        /// <param name="row">DataGridRow</param>
        private void RestoreRow(DataGridRow row)
        {
            BugTraceObject context = row.DataContext as BugTraceObject;

            if (context.Type.Equals("CreateMachine"))
            {
                row.Foreground = new SolidColorBrush(Colors.White);
                row.Background = new SolidColorBrush(Colors.Teal);
            }
            else if (context.Type.Equals("CreateMonitor"))
            {
                row.Foreground = new SolidColorBrush(Colors.White);
                row.Background = new SolidColorBrush(Colors.DarkSlateGray);
            }
            else if (context.Type.Equals("SendEvent"))
            {
                row.Foreground = new SolidColorBrush(Colors.White);
                row.Background = new SolidColorBrush(Colors.RoyalBlue);
            }
            else if (context.Type.Equals("DequeueEvent"))
            {
                row.Foreground = new SolidColorBrush(Colors.White);
                row.Background = new SolidColorBrush(Colors.SteelBlue);
            }
            else if (context.Type.Equals("RaiseEvent"))
            {
                row.Foreground = new SolidColorBrush(Colors.Black);
                row.Background = new SolidColorBrush(Colors.LightSalmon);
            }
            else if (context.Type.Equals("GotoState"))
            {
                row.Foreground = new SolidColorBrush(Colors.Black);
                row.Background = new SolidColorBrush(Colors.Khaki);
            }
            else if (context.Type.Equals("InvokeAction"))
            {
                row.Foreground = new SolidColorBrush(Colors.Black);
                row.Background = new SolidColorBrush(Colors.BurlyWood);
            }
            else if (context.Type.Equals("WaitToReceive"))
            {
                row.Foreground = new SolidColorBrush(Colors.White);
                row.Background = new SolidColorBrush(Colors.DarkOrchid);
            }
            else if (context.Type.Equals("ReceiveEvent"))
            {
                row.Foreground = new SolidColorBrush(Colors.White);
                row.Background = new SolidColorBrush(Colors.DarkOrchid);
            }
            else if (context.Type.Equals("RandomChoice"))
            {
                row.Foreground = new SolidColorBrush(Colors.White);
                row.Background = new SolidColorBrush(Colors.BlueViolet);
            }
            else if (context.Type.Equals("Halt"))
            {
                row.Foreground = new SolidColorBrush(Colors.White);
                row.Background = new SolidColorBrush(Colors.DimGray);
            }

            row.Visibility = Visibility.Visible;
        }
        /// <summary>
        ///     Retrieves the visual tree that was generated for a particular row and column.
        /// </summary>
        /// <param name="dataGridRow">The row that corresponds to the desired cell.</param>
        /// <returns>The element if found, null otherwise.</returns>
        public FrameworkElement GetCellContent(DataGridRow dataGridRow)
        {
            if (dataGridRow == null)
            {
                throw new ArgumentNullException("dataGridRow");
            }

            if (_dataGridOwner != null)
            {
                int columnIndex = _dataGridOwner.Columns.IndexOf(this);
                if (columnIndex >= 0)
                {
                    DataGridCell cell = dataGridRow.TryGetCell(columnIndex);
                    if (cell != null)
                    {
                        return cell.Content as FrameworkElement;
                    }
                }
            }

            return null;
        }
예제 #49
0
 /// <summary>
 /// Selects the specified row.
 /// </summary>
 /// <param name="row">DataGridRow</param>
 private void SelectRow(DataGridRow row)
 {
     row.Foreground = new SolidColorBrush(Colors.White);
     row.Background = new SolidColorBrush(Colors.Black);
 }
 /// <summary>
 ///     Instantiates a new instance of this class.
 /// </summary>
 /// <param name="column">The column of the cell that is about to enter edit mode.</param>
 /// <param name="row">The row container of the cell container that is about to enter edit mode.</param>
 /// <param name="editingEventArgs">The event arguments, if any, that led to the cell entering edit mode.</param>
 public DataGridBeginningEditEventArgs(DataGridColumn column, DataGridRow row, RoutedEventArgs editingEventArgs)
 {
     _dataGridColumn = column;
     _dataGridRow = row;
     _editingEventArgs = editingEventArgs;
 }
예제 #51
0
 /// <summary>
 /// Collapses the specified row.
 /// </summary>
 /// <param name="row">DataGridRow</param>
 private void CollapseRow(DataGridRow row)
 {
     row.Visibility = Visibility.Collapsed;
 }
예제 #52
0
        private static void UpdateCellElement(DataGridColumnBase dataGridColumn, DataGridRow dataGridRow, string propertyName) 
        {
            Debug.Assert(dataGridColumn != null);
            Debug.Assert(dataGridRow != null); 

            DataGridCell dataGridCell = dataGridRow.Cells[dataGridColumn.Index];
            Debug.Assert(dataGridCell != null); 
            FrameworkElement element = dataGridCell.Content as FrameworkElement; 
            if (element != null)
            { 
                dataGridColumn.UpdateElement(element, propertyName);
            }
        } 
예제 #53
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DataGridRow row = value as DataGridRow;

            return(row.GetIndex() + 1);
        }
 // This method is called from DataGrid.OnBeginningEdit/OnCommittingEdit/OnCancelingEdit
 // Raises Invoked event when row begin/cancel/commit edit
 internal void RaiseAutomationRowInvokeEvents(DataGridRow row)
 {
     DataGridItemAutomationPeer dataGridItemAutomationPeer = GetOrCreateItemPeer(row.Item);
     if (dataGridItemAutomationPeer != null)
     {
         dataGridItemAutomationPeer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked);
     }
 }
예제 #55
0
        private void dgTagResults_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            ContextMenu ctMenu     = (ContextMenu)App.Current.MainWindow.FindName("ctMenu");
            Button      btnConnect = (Button)App.Current.MainWindow.FindName("btnConnect");

            try
            {
                if (e.RightButton == MouseButtonState.Pressed)
                {
                    // iteratively traverse the visual tree
                    DependencyObject dep = (DependencyObject)e.OriginalSource;
                    while ((dep != null) && !(dep is DataGridCell) && !(dep is DataGridColumnHeader))
                    {
                        dep = VisualTreeHelper.GetParent(dep);
                    }

                    if (btnConnect.Content != null)
                    {
                        if (btnConnect.Content.ToString() == "Connect" || btnConnect.IsEnabled == false)
                        {
                            ctMenu.Visibility = System.Windows.Visibility.Collapsed;
                            return;
                        }
                    }
                    else if (dep == null)
                    {
                        ctMenu.Visibility = System.Windows.Visibility.Collapsed;
                        return;
                    }

                    if (dep is DataGridCell)
                    {
                        DataGridCell cell = dep as DataGridCell;

                        // navigate further up the tree
                        while ((dep != null) && !(dep is DataGridRow))
                        {
                            dep = VisualTreeHelper.GetParent(dep);
                        }

                        DataGridRow row      = dep as DataGridRow;
                        DataGrid    dataGrid = ItemsControl.ItemsControlFromItemContainer(row) as DataGrid;

                        TagReadRecord tr = (TagReadRecord)row.Item;


                        if ((null != dataGrid.CurrentCell) && (tr.Protocol == TagProtocol.GEN2))
                        {
                            foreach (MenuItem item in ctMenu.Items)
                            {
                                item.IsEnabled = true;
                            }

                            if (dataGrid.CurrentCell.Column.Header.Equals("EPC") || (dataGrid.CurrentCell.Column.Header.Equals("Data")) ||
                                dataGrid.CurrentCell.Column.Header.Equals("EPC(ASCII)") || (dataGrid.CurrentCell.Column.Header.Equals("Data(ASCII)")) ||
                                dataGrid.CurrentCell.Column.Header.Equals("EPC(ReverseBase36)"))
                            {
                                Window mainWindow = App.Current.MainWindow;
                                if (dataGrid.CurrentCell.Column.Header.Equals("EPC") || dataGrid.CurrentCell.Column.Header.Equals("EPC(ASCII)") ||
                                    dataGrid.CurrentCell.Column.Header.Equals("EPC(ReverseBase36)"))
                                {
                                    txtSelectedCell.Text = "EPC";
                                }
                                else
                                {
                                    txtSelectedCell.Text = "Data";
                                }
                                Label lblhiddenembeddedReadvalueFrmMainWdw = (Label)mainWindow.FindName("lblhiddenembeddedReadvalue");
                                ctMenu.Focus();
                                if (lblhiddenembeddedReadvalueFrmMainWdw.Content.ToString() == "Reserved")
                                {
                                    ctMenu.Visibility = System.Windows.Visibility.Collapsed;
                                    Console.WriteLine("Current cell" + dataGrid.CurrentCell.Column.Header.ToString());
                                }
                                else
                                {
                                    ctMenu.Visibility = System.Windows.Visibility.Visible;
                                }
                            }
                            else
                            {
                                ctMenu.Visibility = System.Windows.Visibility.Collapsed;
                                //Console.WriteLine("Else case Current cell" + dataGrid.CurrentCell.Column.Header.ToString());
                            }
                            int index = dataGrid.ItemContainerGenerator.IndexFromContainer(row);
                        }
                        else if ((null != dataGrid.CurrentCell) && (tr.Protocol == TagProtocol.ATA))
                        {
                            foreach (MenuItem item in ctMenu.Items)
                            {
                                if (item.Header.ToString() != "Inspect Tag")
                                {
                                    item.IsEnabled = false;
                                }
                            }
                            ctMenu.Visibility = System.Windows.Visibility.Visible;
                        }
                        else
                        {
                            ctMenu.Visibility = System.Windows.Visibility.Collapsed;
                            //Console.WriteLine("Current Cell is not there" + dataGrid.CurrentCell.Column.Header.ToString());
                        }
                    }
                    else
                    {
                        ctMenu.Visibility = System.Windows.Visibility.Collapsed;
                        //Console.WriteLine("not on a data grid cell" );
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException)
                {
                    ctMenu.Visibility = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
 // This method is called from DataGrid.OnBeginningEdit/OnCommittingEdit/OnCancelingEdit
 // Raises Invoked event when cell begin/cancel/commit edit
 internal void RaiseAutomationCellInvokeEvents(DataGridColumn column, DataGridRow row)
 {
     DataGridItemAutomationPeer dataGridItemAutomationPeer = GetOrCreateItemPeer(row.Item);
     if (dataGridItemAutomationPeer != null)
     {
         DataGridCellItemAutomationPeer cellPeer = dataGridItemAutomationPeer.GetOrCreateCellItemPeer(column);
         if (cellPeer != null)
         {
             cellPeer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked);
         }
     }
 }
예제 #57
0
        /// <summary>
        /// Gets the specified cell of the DataGrid
        /// </summary>
        /// <param name="grid">The DataGrid instance</param>
        /// <param name="row">The row index of the cell</param>
        /// <param name="column">The column index of the cell</param>
        /// <returns>A cell of the DataGrid</returns>
        public static DataGridCell GetCell(this DataGrid grid, int row, int column)
        {
            DataGridRow rowContainer = grid.GetRow(row);

            return(grid.GetCell(rowContainer, column));
        }
예제 #58
0
 /// <summary>
 /// Sets selection in grid
 /// </summary>
 /// <param name="row">row to select</param>
 /// <param name="isChecked">true if checked, false - otherwise</param>
 static void SetSelectionInGrid(DataGridRow row, bool isChecked)
 {
     try
     {
         if (row != null)
         {
             var presenter = WpfExtensions.GetVisualChild<DataGridCellsPresenter>(row);
             DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(0) as DataGridCell;
             if (cell != null)
             {
                 ((CheckBox)cell.Content).IsChecked = isChecked;
             }
         }
     }
     catch
     {
     }
 }
예제 #59
0
        /// <summary>
        /// Measures the children of a <see cref="T:System.Windows.Controls.Primitives.DataGridRowsPresenter" /> to
        /// prepare for arranging them during the <see cref="M:System.Windows.FrameworkElement.ArrangeOverride(System.Windows.Size)" /> pass.
        /// </summary>
        /// <param name="availableSize">
        /// The available size that this element can give to child elements. Indicates an upper limit that child elements should not exceed.
        /// </param>
        /// <returns>
        /// The size that the <see cref="T:System.Windows.Controls.Primitives.DataGridRowsPresenter" /> determines it needs during layout, based on its calculations of child object allocated sizes.
        /// </returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            if (availableSize.Height == 0 || this.OwningGrid == null)
            {
                return(base.MeasureOverride(availableSize));
            }

            // If the Width of our RowsPresenter changed then we need to invalidate our rows
            bool invalidateRows = (!this.OwningGrid.RowsPresenterAvailableSize.HasValue || availableSize.Width != this.OwningGrid.RowsPresenterAvailableSize.Value.Width) &&
                                  !double.IsInfinity(availableSize.Width);

            // The DataGrid uses the RowsPresenter available size in order to autogrow
            // and calculate the scrollbars
            this.OwningGrid.RowsPresenterAvailableSize = availableSize;

            this.OwningGrid.OnRowsMeasure();

            double totalHeight     = -this.OwningGrid.NegVerticalOffset;
            double totalCellsWidth = this.OwningGrid.ColumnsInternal.VisibleEdgedColumnsWidth;

            double headerWidth = 0;

            foreach (UIElement element in this.OwningGrid.DisplayData.GetScrollingElements())
            {
                DataGridRow row = element as DataGridRow;
                if (row != null)
                {
                    if (invalidateRows)
                    {
                        row.InvalidateMeasure();
                    }
                }

                element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                if (row != null && row.HeaderCell != null)
                {
                    headerWidth = Math.Max(headerWidth, row.HeaderCell.DesiredSize.Width);
                }
                else
                {
                    DataGridRowGroupHeader groupHeader = element as DataGridRowGroupHeader;
                    if (groupHeader != null && groupHeader.HeaderCell != null)
                    {
                        headerWidth = Math.Max(headerWidth, groupHeader.HeaderCell.DesiredSize.Width);
                    }
                }

                totalHeight += element.DesiredSize.Height;
            }

            this.OwningGrid.RowHeadersDesiredWidth = headerWidth;
            // Could be positive infinity depending on the DataGrid's bounds
            this.OwningGrid.AvailableSlotElementRoom = availableSize.Height - totalHeight;

            //

            totalHeight = Math.Max(0, totalHeight);

            return(new Size(totalCellsWidth + headerWidth, totalHeight));
        }
 /// <summary>
 ///     Prepares a cell for use.
 /// </summary>
 /// <remarks>
 ///     Updates the column reference.
 ///     This overload computes the column index from the ItemContainerGenerator.
 /// </remarks>
 internal void PrepareCell(object item, ItemsControl cellsPresenter, DataGridRow ownerRow)
 {
     PrepareCell(item, ownerRow, cellsPresenter.ItemContainerGenerator.IndexFromContainer(this));
 }