Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / Automation / Peers / ComboBoxAutomationPeer.cs / 1 / ComboBoxAutomationPeer.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 MS.Internal;
using MS.Win32;
namespace System.Windows.Automation.Peers
{
///
public class ComboBoxAutomationPeer: SelectorAutomationPeer, IValueProvider, IExpandCollapseProvider
{
///
public ComboBoxAutomationPeer(ComboBox owner): base(owner)
{}
///
override protected ItemAutomationPeer CreateItemAutomationPeer(object item)
{
// Use the same peer as ListBox
return new ListBoxItemAutomationPeer(item, this);
}
///
override protected AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.ComboBox;
}
///
override protected string GetClassNameCore()
{
return "ComboBox";
}
///
override public object GetPattern(PatternInterface pattern)
{
object iface = null;
if (pattern == PatternInterface.Value)
{
ComboBox owner = (ComboBox)Owner;
if (owner.IsEditable) iface = this;
}
else if(pattern == PatternInterface.ExpandCollapse)
{
iface = this;
}
else
{
iface = base.GetPattern(pattern);
}
return iface;
}
///
protected override List GetChildrenCore()
{
List children = base.GetChildrenCore();
// include text box part into children collection
ComboBox owner = (ComboBox)Owner;
TextBox textBox = owner.EditableTextBoxSite;
if (textBox != null)
{
AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(textBox);
if (peer != null)
{
if (children == null)
children = new List();
children.Insert(0, peer);
}
}
return children;
}
#region Value
///
/// Request to set the value that this UI element is representing
///
/// Value to set the UI to, as an object
/// true if the UI element was successfully set to the specified value
//[CodeAnalysis("AptcaMethodsShouldOnlyCallAptcaMethods")] //Tracking Bug: 29647
void IValueProvider.SetValue(string val)
{
if (val == null)
throw new ArgumentNullException("val");
ComboBox owner = (ComboBox)Owner;
if (!owner.IsEnabled)
throw new ElementNotEnabledException();
owner.Text = val;
}
///Value of a value control, as a a string.
string IValueProvider.Value
{
get
{
return ((ComboBox)(((ComboBoxAutomationPeer)this).Owner)).Text;
}
}
///Indicates that the value can only be read, not modified.
///returns True if the control is read-only
bool IValueProvider.IsReadOnly
{
get
{
ComboBox owner = (ComboBox)Owner;
return !owner.IsEnabled || owner.IsReadOnly;
}
}
#endregion Value
#region ExpandCollapse
///
/// Blocking method that returns after the element has been expanded.
///
/// true if the node was successfully expanded
void IExpandCollapseProvider.Expand()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
ComboBox owner = (ComboBox)((ComboBoxAutomationPeer)this).Owner;
owner.IsDropDownOpen = true;
}
///
/// Blocking method that returns after the element has been collapsed.
///
/// true if the node was successfully collapsed
void IExpandCollapseProvider.Collapse()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
ComboBox owner = (ComboBox)((ComboBoxAutomationPeer)this).Owner;
owner.IsDropDownOpen = false;
}
///indicates an element's current Collapsed or Expanded state
ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState
{
get
{
ComboBox owner = (ComboBox)((ComboBoxAutomationPeer)this).Owner;
return owner.IsDropDownOpen ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
}
}
//
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal void RaiseExpandCollapseAutomationEvent(bool oldValue, bool newValue)
{
RaisePropertyChangedEvent(
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
oldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed,
newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed);
}
#endregion ExpandCollapse
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
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 MS.Internal;
using MS.Win32;
namespace System.Windows.Automation.Peers
{
///
public class ComboBoxAutomationPeer: SelectorAutomationPeer, IValueProvider, IExpandCollapseProvider
{
///
public ComboBoxAutomationPeer(ComboBox owner): base(owner)
{}
///
override protected ItemAutomationPeer CreateItemAutomationPeer(object item)
{
// Use the same peer as ListBox
return new ListBoxItemAutomationPeer(item, this);
}
///
override protected AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.ComboBox;
}
///
override protected string GetClassNameCore()
{
return "ComboBox";
}
///
override public object GetPattern(PatternInterface pattern)
{
object iface = null;
if (pattern == PatternInterface.Value)
{
ComboBox owner = (ComboBox)Owner;
if (owner.IsEditable) iface = this;
}
else if(pattern == PatternInterface.ExpandCollapse)
{
iface = this;
}
else
{
iface = base.GetPattern(pattern);
}
return iface;
}
///
protected override List GetChildrenCore()
{
List children = base.GetChildrenCore();
// include text box part into children collection
ComboBox owner = (ComboBox)Owner;
TextBox textBox = owner.EditableTextBoxSite;
if (textBox != null)
{
AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(textBox);
if (peer != null)
{
if (children == null)
children = new List();
children.Insert(0, peer);
}
}
return children;
}
#region Value
///
/// Request to set the value that this UI element is representing
///
/// Value to set the UI to, as an object
/// true if the UI element was successfully set to the specified value
//[CodeAnalysis("AptcaMethodsShouldOnlyCallAptcaMethods")] //Tracking Bug: 29647
void IValueProvider.SetValue(string val)
{
if (val == null)
throw new ArgumentNullException("val");
ComboBox owner = (ComboBox)Owner;
if (!owner.IsEnabled)
throw new ElementNotEnabledException();
owner.Text = val;
}
///Value of a value control, as a a string.
string IValueProvider.Value
{
get
{
return ((ComboBox)(((ComboBoxAutomationPeer)this).Owner)).Text;
}
}
///Indicates that the value can only be read, not modified.
///returns True if the control is read-only
bool IValueProvider.IsReadOnly
{
get
{
ComboBox owner = (ComboBox)Owner;
return !owner.IsEnabled || owner.IsReadOnly;
}
}
#endregion Value
#region ExpandCollapse
///
/// Blocking method that returns after the element has been expanded.
///
/// true if the node was successfully expanded
void IExpandCollapseProvider.Expand()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
ComboBox owner = (ComboBox)((ComboBoxAutomationPeer)this).Owner;
owner.IsDropDownOpen = true;
}
///
/// Blocking method that returns after the element has been collapsed.
///
/// true if the node was successfully collapsed
void IExpandCollapseProvider.Collapse()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
ComboBox owner = (ComboBox)((ComboBoxAutomationPeer)this).Owner;
owner.IsDropDownOpen = false;
}
///indicates an element's current Collapsed or Expanded state
ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState
{
get
{
ComboBox owner = (ComboBox)((ComboBoxAutomationPeer)this).Owner;
return owner.IsDropDownOpen ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
}
}
//
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal void RaiseExpandCollapseAutomationEvent(bool oldValue, bool newValue)
{
RaisePropertyChangedEvent(
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
oldValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed,
newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed);
}
#endregion ExpandCollapse
}
}
// 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
- ObjectItemCollection.cs
- ImageUrlEditor.cs
- MimeFormatExtensions.cs
- EnumBuilder.cs
- sqlpipe.cs
- IndexedEnumerable.cs
- PeerName.cs
- XmlQueryStaticData.cs
- Point3DCollectionValueSerializer.cs
- WebBrowserNavigatingEventHandler.cs
- ConnectionPoint.cs
- SharedConnectionInfo.cs
- Geometry.cs
- VisualBasicSettingsHandler.cs
- COM2FontConverter.cs
- HttpRequestCacheValidator.cs
- PhonemeConverter.cs
- ModelProperty.cs
- URLIdentityPermission.cs
- ObjectMaterializedEventArgs.cs
- PublisherIdentityPermission.cs
- DesignerToolStripControlHost.cs
- HttpWebRequestElement.cs
- WebException.cs
- SnapLine.cs
- SchemaElementLookUpTableEnumerator.cs
- FunctionDescription.cs
- SimpleHandlerFactory.cs
- DoubleMinMaxAggregationOperator.cs
- AssociationTypeEmitter.cs
- HybridDictionary.cs
- RequestSecurityTokenResponse.cs
- CodeGroup.cs
- WebPartMinimizeVerb.cs
- HostedImpersonationContext.cs
- OracleTransaction.cs
- SecurityImpersonationBehavior.cs
- _FtpDataStream.cs
- Tracer.cs
- VectorAnimationBase.cs
- ExpressionBindingsDialog.cs
- Block.cs
- DynamicDiscoSearcher.cs
- CookieHandler.cs
- ScrollChrome.cs
- EventLogWatcher.cs
- NodeInfo.cs
- ResourceDisplayNameAttribute.cs
- AutoScrollExpandMessageFilter.cs
- ViewCellSlot.cs
- SslStream.cs
- BitmapInitialize.cs
- RuleSettingsCollection.cs
- DataPagerCommandEventArgs.cs
- Zone.cs
- CaseStatement.cs
- IgnoreDeviceFilterElementCollection.cs
- SectionVisual.cs
- OleDbRowUpdatedEvent.cs
- ArraySortHelper.cs
- Int32CAMarshaler.cs
- ProfessionalColors.cs
- EndOfStreamException.cs
- QuadraticBezierSegment.cs
- SystemSounds.cs
- TypeUtil.cs
- GeometryModel3D.cs
- SHA384.cs
- SimplePropertyEntry.cs
- loginstatus.cs
- OdbcReferenceCollection.cs
- ListViewTableRow.cs
- InputBindingCollection.cs
- DataTableNewRowEvent.cs
- XmlSchemaSimpleTypeList.cs
- PeerNearMe.cs
- TextLineResult.cs
- HttpProfileGroupBase.cs
- AppSecurityManager.cs
- DataTableMappingCollection.cs
- ListControlConvertEventArgs.cs
- ToolStripDropDownClosedEventArgs.cs
- DictionaryContent.cs
- ProfileSection.cs
- MouseActionConverter.cs
- WebHeaderCollection.cs
- X509CertificateChain.cs
- SystemInformation.cs
- ValueUtilsSmi.cs
- XmlSchemaSimpleContent.cs
- ViewCellSlot.cs
- ValidationSummary.cs
- LoginName.cs
- Geometry.cs
- ScriptManagerProxy.cs
- FontFamilyConverter.cs
- DynamicResourceExtension.cs
- KnownTypesProvider.cs
- FlowDocumentPageViewerAutomationPeer.cs
- LookupBindingPropertiesAttribute.cs