コード例 #1
0
        private void ClearChangeIndicator()
        {
            DataGridAutomationPeer automationPeer = (DataGridAutomationPeer)DataGridAutomationPeer.CreatePeerForElement(NodeMetadataDataGrid);

            // Get the DataGridRowsPresenterAutomationPeer so we can find the rows in the data grid...
            DataGridRowsPresenterAutomationPeer dataGridRowsPresenterAutomationPeer = automationPeer.GetChildren().
                                                                                      Where(a => (a is DataGridRowsPresenterAutomationPeer)).
                                                                                      Select(a => (a as DataGridRowsPresenterAutomationPeer)).
                                                                                      FirstOrDefault();

            if (null != dataGridRowsPresenterAutomationPeer)
            {
                foreach (var item in dataGridRowsPresenterAutomationPeer.GetChildren())
                {
                    // loop to find the DataGridCellAutomationPeer from which we can interrogate the owner -- which is a DataGridRow
                    foreach (var subitem in (item as DataGridItemAutomationPeer).GetChildren())
                    {
                        if ((subitem is DataGridCellAutomationPeer))
                        {
                            // At last -- the only public method for finding a row....
                            DataGridRow row = DataGridRow.GetRowContainingElement(((subitem as DataGridCellAutomationPeer).Owner as FrameworkElement));
                            row.Foreground = new SolidColorBrush(Colors.Black);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Scrolls a DataGridRow into view.
        /// </summary>
        /// <param name="itemsControl">The DataGrid containing the row.</param>
        /// <param name="itemContainer">The DataGridRow object.</param>
        protected override void ScrollIntoView(DataGrid itemsControl, DataGridRow itemContainer)
        {
            IScrollProvider scrollInfo = (IScrollProvider)DataGridAutomationPeer.CreatePeerForElement(itemsControl);

            double horizontalScrollPercentBeforeScroll = scrollInfo.HorizontalScrollPercent;
            double verticalScrollPercentBeforeScroll   = scrollInfo.VerticalScrollPercent;

            itemsControl.ScrollIntoView(itemContainer.DataContext, null);

            double horizontalScrollPercentAfterScroll = scrollInfo.HorizontalScrollPercent;
            double verticalScrollPercentAfterScroll   = scrollInfo.VerticalScrollPercent;

            double horizontalDiff = horizontalScrollPercentAfterScroll - horizontalScrollPercentBeforeScroll;
            double verticalDiff   = verticalScrollPercentAfterScroll - verticalScrollPercentBeforeScroll;

            scrollInfo.SetScrollPercent(scrollInfo.HorizontalScrollPercent + (horizontalDiff / 2.0), scrollInfo.VerticalScrollPercent + (verticalDiff / 2.0));
        }
コード例 #3
0
        public DataGridRow GetDataGridRowByDataContext(DataGrid dataGrid, object dataContext)
        {
            if (null != dataContext)
            {
                DataGridAutomationPeer automationPeer = (DataGridAutomationPeer)DataGridAutomationPeer.CreatePeerForElement(dataGrid);

                // Get the DataGridRowsPresenterAutomationPeer so we can find the rows in the data grid...
                DataGridRowsPresenterAutomationPeer dataGridRowsPresenterAutomationPeer = automationPeer.GetChildren().
                                                                                          Where(a => (a is DataGridRowsPresenterAutomationPeer)).
                                                                                          Select(a => (a as DataGridRowsPresenterAutomationPeer)).
                                                                                          FirstOrDefault();

                if (null != dataGridRowsPresenterAutomationPeer)
                {
                    foreach (var item in dataGridRowsPresenterAutomationPeer.GetChildren())
                    {
                        // loop to find the DataGridCellAutomationPeer from which we can interrogate the owner -- which is a DataGridRow
                        foreach (var subitem in (item as DataGridItemAutomationPeer).GetChildren())
                        {
                            if ((subitem is DataGridCellAutomationPeer))
                            {
                                // At last -- the only public method for finding a row....
                                DataGridRow row = DataGridRow.GetRowContainingElement(((subitem as DataGridCellAutomationPeer).Owner as FrameworkElement));

                                // check this row to see if it is bound to the requested dataContext.
                                if ((row.DataContext) == dataContext)
                                {
                                    return(row);
                                }

                                break; // Only need to check one cell in each row
                            }
                        }
                    }
                }
            }

            return(null);
        }