示例#1
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            if (KeysDataGrid.SelectedIndex == -1)
            {
                return;
            }

            var row = (DataGridRow)KeysDataGrid.ItemContainerGenerator.ContainerFromItem(KeysDataGrid.SelectedItem);

            if (row == null)
            {
                return;
            }

            //Getting the ContentPresenter of the row details
            var presenter = VisualHelper.GetVisualChild <DataGridDetailsPresenter>(row);

            if (presenter == null)
            {
                return;
            }

            //Finding Remove button from the DataTemplate that is set on that ContentPresenter
            var template = presenter.ContentTemplate;
            var box      = (KeyBox)template.FindName("AddKeyBox", presenter);

            if (!box.MainKey.HasValue)
            {
                return;
            }

            InternalList[KeysDataGrid.SelectedIndex].KeyList.Add(new SimpleKeyGesture(box.MainKey.Value, box.ModifierKeys, true));
            KeysDataGrid.Items.Refresh();
        }
示例#2
0
    public static DataGridCell GetCell(DataGrid dg, int row, int column)
    {
        var rowContainer = GetRow(dg, row);

        if (rowContainer != null)
        {
            var presenter = VisualHelper.GetVisualChild <DataGridCellsPresenter>(rowContainer);

            // try to get the cell but it may possibly be virtualized
            var cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);

            if (cell == null)
            {
                // now try to bring into view and retrieve the cell
                dg.ScrollIntoView(rowContainer, dg.Columns[column]);
                cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
            }

            return(cell);
        }

        return(null);
    }
 public UICT GetUIControl <UICT>() where UICT : Visual
 {
     return(VisualHelper.GetVisualChild <UICT>(UIElement));
 }