Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Automation / Peers / DatePickerAutomationPeer.cs / 1305600 / DatePickerAutomationPeer.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System.Collections.Generic; using System.Windows.Automation; using System.Windows.Automation.Provider; using System.Windows.Controls; namespace System.Windows.Automation.Peers { ////// AutomationPeer for DatePicker Control /// public sealed class DatePickerAutomationPeer : FrameworkElementAutomationPeer, IExpandCollapseProvider, IValueProvider { ////// Initializes a new instance of the AutomationPeer for DatePicker control. /// /// DatePicker public DatePickerAutomationPeer(DatePicker owner) : base(owner) { } #region Private Properties private DatePicker OwningDatePicker { get { return this.Owner as DatePicker; } } #endregion Private Properties #region Public Methods ////// Gets the control pattern that is associated with the specified System.Windows.Automation.Peers.PatternInterface. /// /// A value from the System.Windows.Automation.Peers.PatternInterface enumeration. ///The object that supports the specified pattern, or null if unsupported. public override object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.ExpandCollapse || patternInterface == PatternInterface.Value) { return this; } return base.GetPattern(patternInterface); } #endregion Public Methods #region Protected Methods protected override void SetFocusCore() { DatePicker owner = OwningDatePicker; if (owner.Focusable) { if (!owner.Focus()) { TextBox tb = owner.TextBox; //The focus should have gone to the TextBox inside DatePicker if (tb == null || !tb.IsKeyboardFocused) { throw new InvalidOperationException(SR.Get(SRID.SetFocusFailed)); } } } else { throw new InvalidOperationException(SR.Get(SRID.SetFocusFailed)); } } ////// Gets the control type for the element that is associated with the UI Automation peer. /// ///The control type. protected override AutomationControlType GetAutomationControlTypeCore() { return AutomationControlType.Custom; } protected override ListGetChildrenCore() { List children = base.GetChildrenCore(); if (OwningDatePicker.IsDropDownOpen && OwningDatePicker.Calendar != null) { CalendarAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(OwningDatePicker.Calendar) as CalendarAutomationPeer; if (peer != null) { children.Add(peer); } } return children; } /// /// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType, /// differentiates the control represented by this AutomationPeer. /// ///The string that contains the name. protected override string GetClassNameCore() { return Owner.GetType().Name; } ////// Overrides the GetLocalizedControlTypeCore method for DatePicker /// ///protected override string GetLocalizedControlTypeCore() { return SR.Get(SRID.DatePickerAutomationPeer_LocalizedControlType); } #endregion Protected Methods #region IExpandCollapseProvider ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState { get { if (this.OwningDatePicker.IsDropDownOpen) { return ExpandCollapseState.Expanded; } else { return ExpandCollapseState.Collapsed; } } } void IExpandCollapseProvider.Collapse() { this.OwningDatePicker.IsDropDownOpen = false; } void IExpandCollapseProvider.Expand() { this.OwningDatePicker.IsDropDownOpen = true; } #endregion IExpandCollapseProvider #region IValueProvider bool IValueProvider.IsReadOnly { get { return false; } } string IValueProvider.Value { get { return this.OwningDatePicker.ToString(); } } void IValueProvider.SetValue(string value) { this.OwningDatePicker.Text = value; } #endregion IValueProvider #region Internal Methods // Never inline, as we don't want to unnecessarily link the automation DLL [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] internal void RaiseValuePropertyChangedEvent(string oldValue, string newValue) { if (oldValue != newValue) { RaisePropertyChangedEvent(ValuePatternIdentifiers.ValueProperty, oldValue, newValue); } } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System.Collections.Generic; using System.Windows.Automation; using System.Windows.Automation.Provider; using System.Windows.Controls; namespace System.Windows.Automation.Peers { /// /// AutomationPeer for DatePicker Control /// public sealed class DatePickerAutomationPeer : FrameworkElementAutomationPeer, IExpandCollapseProvider, IValueProvider { ////// Initializes a new instance of the AutomationPeer for DatePicker control. /// /// DatePicker public DatePickerAutomationPeer(DatePicker owner) : base(owner) { } #region Private Properties private DatePicker OwningDatePicker { get { return this.Owner as DatePicker; } } #endregion Private Properties #region Public Methods ////// Gets the control pattern that is associated with the specified System.Windows.Automation.Peers.PatternInterface. /// /// A value from the System.Windows.Automation.Peers.PatternInterface enumeration. ///The object that supports the specified pattern, or null if unsupported. public override object GetPattern(PatternInterface patternInterface) { if (patternInterface == PatternInterface.ExpandCollapse || patternInterface == PatternInterface.Value) { return this; } return base.GetPattern(patternInterface); } #endregion Public Methods #region Protected Methods protected override void SetFocusCore() { DatePicker owner = OwningDatePicker; if (owner.Focusable) { if (!owner.Focus()) { TextBox tb = owner.TextBox; //The focus should have gone to the TextBox inside DatePicker if (tb == null || !tb.IsKeyboardFocused) { throw new InvalidOperationException(SR.Get(SRID.SetFocusFailed)); } } } else { throw new InvalidOperationException(SR.Get(SRID.SetFocusFailed)); } } ////// Gets the control type for the element that is associated with the UI Automation peer. /// ///The control type. protected override AutomationControlType GetAutomationControlTypeCore() { return AutomationControlType.Custom; } protected override ListGetChildrenCore() { List children = base.GetChildrenCore(); if (OwningDatePicker.IsDropDownOpen && OwningDatePicker.Calendar != null) { CalendarAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(OwningDatePicker.Calendar) as CalendarAutomationPeer; if (peer != null) { children.Add(peer); } } return children; } /// /// Called by GetClassName that gets a human readable name that, in addition to AutomationControlType, /// differentiates the control represented by this AutomationPeer. /// ///The string that contains the name. protected override string GetClassNameCore() { return Owner.GetType().Name; } ////// Overrides the GetLocalizedControlTypeCore method for DatePicker /// ///protected override string GetLocalizedControlTypeCore() { return SR.Get(SRID.DatePickerAutomationPeer_LocalizedControlType); } #endregion Protected Methods #region IExpandCollapseProvider ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState { get { if (this.OwningDatePicker.IsDropDownOpen) { return ExpandCollapseState.Expanded; } else { return ExpandCollapseState.Collapsed; } } } void IExpandCollapseProvider.Collapse() { this.OwningDatePicker.IsDropDownOpen = false; } void IExpandCollapseProvider.Expand() { this.OwningDatePicker.IsDropDownOpen = true; } #endregion IExpandCollapseProvider #region IValueProvider bool IValueProvider.IsReadOnly { get { return false; } } string IValueProvider.Value { get { return this.OwningDatePicker.ToString(); } } void IValueProvider.SetValue(string value) { this.OwningDatePicker.Text = value; } #endregion IValueProvider #region Internal Methods // Never inline, as we don't want to unnecessarily link the automation DLL [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] internal void RaiseValuePropertyChangedEvent(string oldValue, string newValue) { if (oldValue != newValue) { RaisePropertyChangedEvent(ValuePatternIdentifiers.ValueProperty, oldValue, newValue); } } #endregion } } // 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
- TrackingMemoryStream.cs
- HostSecurityManager.cs
- SchemaNamespaceManager.cs
- XmlSchemaInferenceException.cs
- BrowserDefinitionCollection.cs
- ReferentialConstraint.cs
- SHA384.cs
- ItemsPanelTemplate.cs
- NamespaceDecl.cs
- AttributeExtensions.cs
- InternalConfigEventArgs.cs
- ProgressiveCrcCalculatingStream.cs
- ListBindingConverter.cs
- BodyWriter.cs
- DataSourceExpressionCollection.cs
- Range.cs
- Focus.cs
- UrlMapping.cs
- CodeVariableReferenceExpression.cs
- BufferBuilder.cs
- MergeLocalizationDirectives.cs
- SerializationException.cs
- LifetimeServices.cs
- ToolboxControl.cs
- PasswordRecovery.cs
- PermissionSetEnumerator.cs
- SignatureSummaryDialog.cs
- TextRunTypographyProperties.cs
- MD5CryptoServiceProvider.cs
- InputLanguageProfileNotifySink.cs
- QueryExpr.cs
- BulletedListEventArgs.cs
- XmlMembersMapping.cs
- FixUpCollection.cs
- PrinterSettings.cs
- Registry.cs
- BitStream.cs
- ObjectManager.cs
- WebCategoryAttribute.cs
- SqlVersion.cs
- WeakRefEnumerator.cs
- WorkflowServiceOperationListItem.cs
- PrintDialog.cs
- MediaScriptCommandRoutedEventArgs.cs
- PointHitTestResult.cs
- CookieHandler.cs
- ErrorTolerantObjectWriter.cs
- ChangeBlockUndoRecord.cs
- invalidudtexception.cs
- ListManagerBindingsCollection.cs
- DataError.cs
- InternalPermissions.cs
- StylusButtonEventArgs.cs
- Semaphore.cs
- DataDocumentXPathNavigator.cs
- SafeEventHandle.cs
- GridViewRow.cs
- MimeTypePropertyAttribute.cs
- EnumBuilder.cs
- Misc.cs
- ByteConverter.cs
- MasterPage.cs
- QualifiedCellIdBoolean.cs
- ResizeBehavior.cs
- Vars.cs
- OutputCacheSettings.cs
- DecimalAnimationBase.cs
- Stack.cs
- HealthMonitoringSectionHelper.cs
- DiscoveryInnerClientManaged11.cs
- StructuredTypeEmitter.cs
- ParameterElementCollection.cs
- WebConfigurationManager.cs
- DocumentPageView.cs
- KnownTypesProvider.cs
- ObjectConverter.cs
- StructuredProperty.cs
- SqlDataSourceFilteringEventArgs.cs
- SecurityTokenResolver.cs
- SelectionRangeConverter.cs
- BitmapSourceSafeMILHandle.cs
- sqlcontext.cs
- SpeechUI.cs
- SimpleType.cs
- XPathBuilder.cs
- CodeSnippetTypeMember.cs
- IdleTimeoutMonitor.cs
- Misc.cs
- XPathEmptyIterator.cs
- ResourcePool.cs
- CommandDesigner.cs
- CompatibleComparer.cs
- DisposableCollectionWrapper.cs
- Point3DCollectionValueSerializer.cs
- HttpAsyncResult.cs
- ShaderRenderModeValidation.cs
- LinkedResource.cs
- SafeLocalMemHandle.cs
- BrowserDefinition.cs
- JapaneseLunisolarCalendar.cs