Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Automation / Peers / ItemAutomationPeer.cs / 1407647 / ItemAutomationPeer.cs
using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Security; using System.Text; using System.Windows; using System.Windows.Automation.Provider; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; using MS.Internal; using MS.Win32; namespace System.Windows.Automation.Peers { ////// Earlier this class was returning the default value for all properties when there is no wrapper/when it is virtualized, /// now it will throw ElementNotAvailableException (leaving some exceptions, like properties supported by container to find elements) /// to notify the client that the full Element does not exist yet. Client may decide to use VirtualizedItemPattern to realize the full item /// public abstract class ItemAutomationPeer : AutomationPeer, IVirtualizedItemProvider { /// protected ItemAutomationPeer(object item, ItemsControlAutomationPeer itemsControlAutomationPeer): base() { _item = item; _itemsControlAutomationPeer = itemsControlAutomationPeer; } /// internal override bool AncestorsInvalid { get { return base.AncestorsInvalid; } set { base.AncestorsInvalid = value; if (value) return; AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) { wrapperPeer.AncestorsInvalid = false; } } } /// override public object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.VirtualizedItem) { // Virtualization not supported for GriViewItem or when Grouping is enabled if(VirtualizedItemPatternIdentifiers.Pattern != null && !(this is GridViewItemAutomationPeer) && !IsGroupingEnabled()) { if(GetWrapperPeer() == null) return this; else { // ItemsControlAutomationPeer can be null in case of TreeViewItems when parent TreeViewItem is also virtualized // If the Item is in Automation Tree we consider it has Realized and need not return VirtualizeItem pattern. if(ItemsControlAutomationPeer != null && !IsItemInAutomationTree()) { return this; } if(ItemsControlAutomationPeer == null) return this; } } return null; } else if(patternInterface == PatternInterface.SynchronizedInput) { UIElementAutomationPeer peer = GetWrapperPeer() as UIElementAutomationPeer; if(peer != null) { return peer.GetPattern(patternInterface); } } return null; } internal UIElement GetWrapper() { UIElement wrapper = null; ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer; if (itemsControlAutomationPeer != null) { ItemsControl owner = (ItemsControl)(itemsControlAutomationPeer.Owner); if (owner != null) { if (((MS.Internal.Controls.IGeneratorHost)owner).IsItemItsOwnContainer(_item)) wrapper = _item as UIElement; else wrapper = owner.ItemContainerGenerator.ContainerFromItem(_item) as UIElement; } } return wrapper; } virtual internal AutomationPeer GetWrapperPeer() { AutomationPeer wrapperPeer = null; UIElement wrapper = GetWrapper(); if(wrapper != null) { wrapperPeer = UIElementAutomationPeer.CreatePeerForElement(wrapper); if(wrapperPeer == null) //fall back to default peer if there is no specific one { if(wrapper is FrameworkElement) wrapperPeer = new FrameworkElementAutomationPeer((FrameworkElement)wrapper); else wrapperPeer = new UIElementAutomationPeer(wrapper); } } return wrapperPeer; } ///internal void ThrowElementNotAvailableException() { // To avoid the situation on legacy systems which may not have new unmanaged core. this check with old unmanaged core // avoids throwing exception and provide older behavior returning default values for items which are virtualized rather than throwing exception. if (!IsGroupingEnabled() && VirtualizedItemPatternIdentifiers.Pattern != null && !(this is GridViewItemAutomationPeer) && !IsItemInAutomationTree()) throw new ElementNotAvailableException(SR.Get(SRID.VirtualizedElement)); } private bool IsGroupingEnabled() { ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer; if(itemsControlAutomationPeer != null && (itemsControlAutomationPeer.Owner as ItemsControl).IsGrouping == true) return true; return false; } private bool IsItemInAutomationTree() { AutomationPeer parent = this.GetParent(); if(this.Index != -1 && parent != null && parent.Children != null && this.Index < parent.Children.Count && parent.Children[this.Index] == this) return true; else return false; } override internal bool IsDataItemAutomationPeer() { return true; } override internal void AddToParentProxyWeakRefCache() { ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer; if(itemsControlAutomationPeer != null) { itemsControlAutomationPeer.AddProxyToWeakRefStorage(this.ElementProxyWeakReference, this); } } /// override internal Rect GetVisibleBoundingRectCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) { return wrapperPeer.GetVisibleBoundingRectCore(); } return GetBoundingRectangle(); } /// override protected string GetItemTypeCore() { return string.Empty; } /// protected override List GetChildrenCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) { // The children needs to be updated before GetChildren call as ChildrenValid flag would already be true and GetChildren call won't update the children list. wrapperPeer.ForceEnsureChildren(); List children = wrapperPeer.GetChildren(); return children; } return null; } /// protected override Rect GetBoundingRectangleCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) { return wrapperPeer.GetBoundingRectangle(); } else ThrowElementNotAvailableException(); return new Rect(); } /// protected override bool IsOffscreenCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.IsOffscreen(); else ThrowElementNotAvailableException(); return true; } /// protected override AutomationOrientation GetOrientationCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.GetOrientation(); else ThrowElementNotAvailableException(); return AutomationOrientation.None; } /// protected override string GetItemStatusCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.GetItemStatus(); else ThrowElementNotAvailableException(); return string.Empty; } /// protected override bool IsRequiredForFormCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.IsRequiredForForm(); else ThrowElementNotAvailableException(); return false; } /// protected override bool IsKeyboardFocusableCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.IsKeyboardFocusable(); else ThrowElementNotAvailableException(); return false; } /// protected override bool HasKeyboardFocusCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.HasKeyboardFocus(); else ThrowElementNotAvailableException(); return false; } /// protected override bool IsEnabledCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.IsEnabled(); else ThrowElementNotAvailableException(); return false; } /// protected override bool IsPasswordCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.IsPassword(); else ThrowElementNotAvailableException(); return false; } /// protected override string GetAutomationIdCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.GetAutomationId(); else ThrowElementNotAvailableException(); return string.Empty; } /// protected override string GetNameCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); string name = null; if (wrapperPeer != null) name = wrapperPeer.GetName(); if (string.IsNullOrEmpty(name) && _item != null) { // For FE we can't use ToString as that provides extraneous information than just the plain text FrameworkElement fe = _item as FrameworkElement; if(fe != null) name = fe.GetPlainText(); if(string.IsNullOrEmpty(name)) name = _item.ToString(); } return name; } /// protected override bool IsContentElementCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.IsContentElement(); return true; } /// protected override bool IsControlElementCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.IsControlElement(); return true; } /// protected override AutomationPeer GetLabeledByCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.GetLabeledBy(); else ThrowElementNotAvailableException(); return null; } /// protected override string GetHelpTextCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.GetHelpText(); else ThrowElementNotAvailableException(); return string.Empty; } /// protected override string GetAcceleratorKeyCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.GetAcceleratorKey(); else ThrowElementNotAvailableException(); return string.Empty; } /// protected override string GetAccessKeyCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.GetAccessKey(); else ThrowElementNotAvailableException(); return string.Empty; } /// protected override Point GetClickablePointCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) return wrapperPeer.GetClickablePoint(); else ThrowElementNotAvailableException(); return new Point(double.NaN, double.NaN); } /// protected override void SetFocusCore() { AutomationPeer wrapperPeer = GetWrapperPeer(); if (wrapperPeer != null) wrapperPeer.SetFocus(); else ThrowElementNotAvailableException(); } virtual internal ItemsControlAutomationPeer GetItemsControlAutomationPeer() { return _itemsControlAutomationPeer; } /// public object Item { get { return _item; } } /// public ItemsControlAutomationPeer ItemsControlAutomationPeer { get { return GetItemsControlAutomationPeer(); } internal set { _itemsControlAutomationPeer = value; } } /// void IVirtualizedItemProvider.Realize() { RealizeCore(); } virtual internal void RealizeCore() { ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer; if (itemsControlAutomationPeer != null) { ItemsControl parent = itemsControlAutomationPeer.Owner as ItemsControl; if (parent != null) { if (parent.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) { parent.OnBringItemIntoView(Item); } else { // The items aren't generated, try at a later time Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(parent.OnBringItemIntoView), Item); } } } } private object _item; private ItemsControlAutomationPeer _itemsControlAutomationPeer; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SHA256Managed.cs
- XmlMapping.cs
- BitmapSourceSafeMILHandle.cs
- AssemblyGen.cs
- DesignerProperties.cs
- SoapUnknownHeader.cs
- StreamWriter.cs
- HelpEvent.cs
- Metafile.cs
- TextFormatterContext.cs
- ManagedCodeMarkers.cs
- TranslateTransform3D.cs
- SqlBooleanMismatchVisitor.cs
- _FtpDataStream.cs
- isolationinterop.cs
- ContentIterators.cs
- RoleGroupCollection.cs
- WmlTextBoxAdapter.cs
- BaseInfoTable.cs
- RijndaelManagedTransform.cs
- Renderer.cs
- PeerCustomResolverElement.cs
- SiteMapPathDesigner.cs
- CompiledQueryCacheKey.cs
- RichTextBoxContextMenu.cs
- RequestDescription.cs
- VectorAnimation.cs
- WebServiceParameterData.cs
- GenerateHelper.cs
- FlowDocumentReaderAutomationPeer.cs
- MediaScriptCommandRoutedEventArgs.cs
- MonthChangedEventArgs.cs
- FormatterServices.cs
- TextRunCacheImp.cs
- SiteMapNodeItem.cs
- CompositeCollection.cs
- CacheOutputQuery.cs
- ModelVisual3D.cs
- AssemblySettingAttributes.cs
- SmtpAuthenticationManager.cs
- ImageIndexConverter.cs
- NavigationWindow.cs
- DependencyPropertyKind.cs
- SafeNativeMethodsCLR.cs
- NumberFunctions.cs
- HttpModuleCollection.cs
- ServicePointManager.cs
- FilteredAttributeCollection.cs
- RemotingSurrogateSelector.cs
- PageBuildProvider.cs
- ButtonColumn.cs
- TextEditorLists.cs
- XmlEventCache.cs
- UniqueIdentifierService.cs
- ServerIdentity.cs
- DataTrigger.cs
- Duration.cs
- WizardStepCollectionEditor.cs
- FileReader.cs
- Color.cs
- PreviewPrintController.cs
- CatalogPartDesigner.cs
- CommentEmitter.cs
- XPathNodeInfoAtom.cs
- BitmapEffectDrawingContent.cs
- EmptyStringExpandableObjectConverter.cs
- WebRequestModulesSection.cs
- SoapUnknownHeader.cs
- SqlBulkCopyColumnMapping.cs
- InvalidOleVariantTypeException.cs
- ResizeBehavior.cs
- FormsAuthenticationEventArgs.cs
- InputScope.cs
- ConstraintManager.cs
- LayoutUtils.cs
- VisualSerializer.cs
- FrugalMap.cs
- IntellisenseTextBox.designer.cs
- FileChangesMonitor.cs
- DrawItemEvent.cs
- ListItemCollection.cs
- BitmapEffectGroup.cs
- SimpleType.cs
- SectionInput.cs
- PageSetupDialog.cs
- DataServiceQueryOfT.cs
- SmiConnection.cs
- Console.cs
- InvokeMethodActivity.cs
- ToolStripCodeDomSerializer.cs
- AppDomainManager.cs
- ClockGroup.cs
- CompositeScriptReferenceEventArgs.cs
- NativeMethods.cs
- RestHandlerFactory.cs
- SchemaTableOptionalColumn.cs
- SystemColors.cs
- NavigationHelper.cs
- ECDiffieHellmanCng.cs
- WizardPanel.cs