public void DataGridRowsPresenter_AutomationPeer() { List<Customer> boundList = CreateCustomerList(15); DataGrid dataGrid = new DataGrid(); Assert.IsNotNull(dataGrid); isLoaded = false; dataGrid.Width = 350; dataGrid.Height = 250; dataGrid.Loaded += new RoutedEventHandler(dataGrid_Loaded); dataGrid.AutoGenerateColumns = true; DataGridRowsPresenter rowsPresenter = new DataGridRowsPresenter(); TestPanel.Children.Add(dataGrid); TestPanel.Children.Add(rowsPresenter); EnqueueConditional(delegate { return isLoaded; }); this.EnqueueYieldThread(); AutomationPeer peer = null; EnqueueCallback(delegate { peer = DataGridAutomationPeer.CreatePeerForElement(dataGrid.TestHook.RowsPresenter); Assert.IsNotNull(peer); Assert.AreEqual(typeof(DataGridRowsPresenter).Name, peer.GetClassName(), "Incorrect ClassName value"); Assert.AreEqual(AutomationControlType.Custom, peer.GetAutomationControlType(), "Incorrect ControlType value"); Assert.AreEqual(false, peer.IsContentElement(), "Incorrect IsContentElement value"); Assert.AreEqual(true, peer.IsControlElement(), "Incorrect IsControlElement value"); Assert.AreEqual(false, peer.IsKeyboardFocusable(), "Incorrect IsKeyBoardFocusable value"); Assert.IsNotNull(peer.GetChildren(), "GetChildren should never return null"); Assert.AreEqual(0, peer.GetChildren().Count, "Incorrect number of children"); dataGrid.ItemsSource = boundList; }); this.EnqueueYieldThread(); EnqueueCallback(delegate { // After setting the ItemsSource, GetChildren should return boundList.Count number of elements Assert.AreEqual(boundList.Count, peer.GetChildren().Count, "Incorrect number of children"); // Check that an unattached RowsPresenter does not return null for GetChildren. peer = DataGridAutomationPeer.CreatePeerForElement(rowsPresenter); Assert.IsNotNull(peer); Assert.IsNotNull(peer.GetChildren(), "GetChildren should never return null"); Assert.AreEqual(0, peer.GetChildren().Count, "Empty RowsPresenter should have no children"); }); EnqueueTestComplete(); }
/// <summary> /// Builds the visual tree for the column header when a new template is applied. /// </summary> public override void OnApplyTemplate() { // The template has changed, so we need to refresh the visuals this._measured = false; if (this._columnHeadersPresenter != null) { // If we're applying a new template, we want to remove the old column headers first this._columnHeadersPresenter.Children.Clear(); } _columnHeadersPresenter = GetTemplateChild(DATAGRID_elementColumnHeadersPresenterName) as DataGridColumnHeadersPresenter; if (_columnHeadersPresenter != null) { if (this.ColumnsInternal.FillerColumn != null) { this.ColumnsInternal.FillerColumn.IsRepresented = false; } _columnHeadersPresenter.OwningGrid = this; // Columns were added before before our Template was applied, add the ColumnHeaders now foreach (DataGridColumn column in this.ColumnsItemsInternal) { InsertDisplayedColumnHeader(column); } } if (this._rowsPresenter != null) { // If we're applying a new template, we want to remove the old rows first this.UnloadElements(false /*recycle*/); } _rowsPresenter = GetTemplateChild(DATAGRID_elementRowsPresenterName) as DataGridRowsPresenter; if (_rowsPresenter != null) { _rowsPresenter.OwningGrid = this; InvalidateRowHeightEstimate(); UpdateRowDetailsHeightEstimate(); } _frozenColumnScrollBarSpacer = GetTemplateChild(DATAGRID_elementFrozenColumnScrollBarSpacerName) as FrameworkElement; if (_hScrollBar != null) { _hScrollBar.Scroll -= new ScrollEventHandler(HorizontalScrollBar_Scroll); } _hScrollBar = GetTemplateChild(DATAGRID_elementHorizontalScrollbarName) as ScrollBar; if (_hScrollBar != null) { _hScrollBar.IsTabStop = false; _hScrollBar.Maximum = 0.0; _hScrollBar.Orientation = Orientation.Horizontal; _hScrollBar.Visibility = Visibility.Collapsed; _hScrollBar.Scroll += new ScrollEventHandler(HorizontalScrollBar_Scroll); } if (_vScrollBar != null) { _vScrollBar.Scroll -= new ScrollEventHandler(VerticalScrollBar_Scroll); } _vScrollBar = GetTemplateChild(DATAGRID_elementVerticalScrollbarName) as ScrollBar; if (_vScrollBar != null) { _vScrollBar.IsTabStop = false; _vScrollBar.Maximum = 0.0; _vScrollBar.Orientation = Orientation.Vertical; _vScrollBar.Visibility = Visibility.Collapsed; _vScrollBar.Scroll += new ScrollEventHandler(VerticalScrollBar_Scroll); } _topLeftCornerHeader = GetTemplateChild(DATAGRID_elementTopLeftCornerHeaderName) as ContentControl; EnsureTopLeftCornerHeader(); // EnsureTopLeftCornerHeader checks for a null _topLeftCornerHeader; _topRightCornerHeader = GetTemplateChild(DATAGRID_elementTopRightCornerHeaderName) as ContentControl; if (this._validationSummary != null) { this._validationSummary.FocusingInvalidControl -= new EventHandler<FocusingInvalidControlEventArgs>(ValidationSummary_FocusingInvalidControl); this._validationSummary.SelectionChanged -= new EventHandler<SelectionChangedEventArgs>(ValidationSummary_SelectionChanged); } this._validationSummary = GetTemplateChild(DATAGRID_elementValidationSummary) as ValidationSummary; if (this._validationSummary != null) { // The ValidationSummary defaults to using its parent if Target is null, so the only // way to prevent it from automatically picking up errors is to set it to some useless element. if (this._validationSummary.Target == null) { this._validationSummary.Target = new Rectangle(); } this._validationSummary.FocusingInvalidControl += new EventHandler<FocusingInvalidControlEventArgs>(ValidationSummary_FocusingInvalidControl); this._validationSummary.SelectionChanged += new EventHandler<SelectionChangedEventArgs>(ValidationSummary_SelectionChanged); if (DesignerProperties.IsInDesignTool) { Debug.Assert(this._validationSummary.Errors != null); // Do not add the default design time errors when in design mode. this._validationSummary.Errors.Clear(); } } UpdateDisabledVisual(); }
/// <summary> /// AutomationPeer for DataGridColumnHeadersPresenter /// </summary> /// <param name="owner">DataGridColumnHeadersPresenter</param> public DataGridRowsPresenterAutomationPeer(DataGridRowsPresenter owner) : base(owner) { }
public override void OnApplyTemplate() { _columnHeadersPresenter = GetTemplateChild(DATAGRID_elementColumnHeadersPresenterName) as DataGridColumnHeadersPresenter; if (_columnHeadersPresenter != null) { _columnHeadersPresenter.OwningGrid = this; // Columns were added before before our Template was applied, add the ColumnHeaders now foreach (DataGridColumn column in this.ColumnsInternal) { InsertDisplayedColumnHeader(column); } } _rowsPresenter = GetTemplateChild(DATAGRID_elementRowsPresenterName) as DataGridRowsPresenter; if (_rowsPresenter != null) { _rowsPresenter.OwningGrid = this; InvalidateRowHeightEstimate(); UpdateRowDetailsHeightEstimate(); } _frozenColumnScrollBarSpacer = GetTemplateChild(DATAGRID_elementFrozenColumnScrollBarSpacerName) as FrameworkElement; _hScrollBar = GetTemplateChild(DATAGRID_elementHorizontalScrollbarName) as ScrollBar; if (_hScrollBar != null) { _hScrollBar.IsTabStop = false; _hScrollBar.Maximum = 0.0; _hScrollBar.Orientation = Orientation.Horizontal; _hScrollBar.Visibility = Visibility.Collapsed; _hScrollBar.Scroll += new ScrollEventHandler(HorizontalScrollBar_Scroll); } _vScrollBar = GetTemplateChild(DATAGRID_elementVerticalScrollbarName) as ScrollBar; if (_vScrollBar != null) { _vScrollBar.IsTabStop = false; _vScrollBar.Maximum = 0.0; _vScrollBar.Orientation = Orientation.Vertical; _vScrollBar.Visibility = Visibility.Collapsed; _vScrollBar.Scroll += new ScrollEventHandler(VerticalScrollBar_Scroll); } _topLeftCornerHeader = GetTemplateChild(DATAGRID_elementTopLeftCornerHeaderName) as ContentControl; EnsureTopLeftCornerHeader(); // EnsureTopLeftCornerHeader checks for a null _topLeftCornerHeader; _topRightCornerHeader = GetTemplateChild(DATAGRID_elementTopRightCornerHeaderName) as ContentControl; }