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 / TreeViewItemAutomationPeer.cs / 1 / TreeViewItemAutomationPeer.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 TreeViewItemAutomationPeer : FrameworkElementAutomationPeer, IExpandCollapseProvider, ISelectionItemProvider, IScrollItemProvider
{
///
public TreeViewItemAutomationPeer(TreeViewItem owner): base(owner)
{
}
///
override protected string GetClassNameCore()
{
return "TreeViewItem";
}
///
override protected AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.TreeItem;
}
///
override public object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.ExpandCollapse)
{
return this;
}
else if (patternInterface == PatternInterface.SelectionItem)
{
return this;
}
else if (patternInterface == PatternInterface.ScrollItem)
{
return this;
}
return null;
}
///
void IExpandCollapseProvider.Expand()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
TreeViewItem treeViewItem = (TreeViewItem)Owner;
if (!treeViewItem.HasItems)
{
throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed));
}
treeViewItem.IsExpanded = true;
}
///
void IExpandCollapseProvider.Collapse()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
TreeViewItem treeViewItem = (TreeViewItem)Owner;
if (!treeViewItem.HasItems)
{
throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed));
}
treeViewItem.IsExpanded = false;
}
ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState
{
get
{
TreeViewItem treeViewItem = (TreeViewItem)Owner;
if (treeViewItem.HasItems)
return treeViewItem.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
else
return ExpandCollapseState.LeafNode;
}
}
//
[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);
}
#region ISelectionItemProvider
///
/// Selects this element, removing any other element from the selection.
///
void ISelectionItemProvider.Select()
{
((TreeViewItem)Owner).IsSelected = true;
}
///
/// Selects this item.
///
void ISelectionItemProvider.AddToSelection()
{
TreeView treeView = ((TreeViewItem)Owner).ParentTreeView;
// If TreeView already has a selected item different from current - we cannot add to selection and throw
if (treeView == null || (treeView.SelectedItem != null && treeView.SelectedContainer != Owner))
{
throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed));
}
((TreeViewItem)Owner).IsSelected = true;
}
///
/// Unselects this item.
///
void ISelectionItemProvider.RemoveFromSelection()
{
((TreeViewItem)Owner).IsSelected = false;
}
///
/// Returns whether the item is selected.
///
bool ISelectionItemProvider.IsSelected
{
get
{
return ((TreeViewItem)Owner).IsSelected;
}
}
///
/// The logical element that supports the SelectionPattern for this item.
///
IRawElementProviderSimple ISelectionItemProvider.SelectionContainer
{
get
{
ItemsControl parent = ((TreeViewItem)Owner).ParentItemsControl;
if (parent != null)
{
AutomationPeer peer = UIElementAutomationPeer.FromElement(parent);
if (peer != null)
return ProviderFromPeer(peer);
}
return null;
}
}
void IScrollItemProvider.ScrollIntoView()
{
((TreeViewItem)Owner).BringIntoView();
}
//
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal void RaiseAutomationIsSelectedChanged(bool isSelected)
{
RaisePropertyChangedEvent(
SelectionItemPatternIdentifiers.IsSelectedProperty,
!isSelected,
isSelected);
}
#endregion
}
}
// 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 TreeViewItemAutomationPeer : FrameworkElementAutomationPeer, IExpandCollapseProvider, ISelectionItemProvider, IScrollItemProvider
{
///
public TreeViewItemAutomationPeer(TreeViewItem owner): base(owner)
{
}
///
override protected string GetClassNameCore()
{
return "TreeViewItem";
}
///
override protected AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.TreeItem;
}
///
override public object GetPattern(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.ExpandCollapse)
{
return this;
}
else if (patternInterface == PatternInterface.SelectionItem)
{
return this;
}
else if (patternInterface == PatternInterface.ScrollItem)
{
return this;
}
return null;
}
///
void IExpandCollapseProvider.Expand()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
TreeViewItem treeViewItem = (TreeViewItem)Owner;
if (!treeViewItem.HasItems)
{
throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed));
}
treeViewItem.IsExpanded = true;
}
///
void IExpandCollapseProvider.Collapse()
{
if(!IsEnabled())
throw new ElementNotEnabledException();
TreeViewItem treeViewItem = (TreeViewItem)Owner;
if (!treeViewItem.HasItems)
{
throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed));
}
treeViewItem.IsExpanded = false;
}
ExpandCollapseState IExpandCollapseProvider.ExpandCollapseState
{
get
{
TreeViewItem treeViewItem = (TreeViewItem)Owner;
if (treeViewItem.HasItems)
return treeViewItem.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
else
return ExpandCollapseState.LeafNode;
}
}
//
[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);
}
#region ISelectionItemProvider
///
/// Selects this element, removing any other element from the selection.
///
void ISelectionItemProvider.Select()
{
((TreeViewItem)Owner).IsSelected = true;
}
///
/// Selects this item.
///
void ISelectionItemProvider.AddToSelection()
{
TreeView treeView = ((TreeViewItem)Owner).ParentTreeView;
// If TreeView already has a selected item different from current - we cannot add to selection and throw
if (treeView == null || (treeView.SelectedItem != null && treeView.SelectedContainer != Owner))
{
throw new InvalidOperationException(SR.Get(SRID.UIA_OperationCannotBePerformed));
}
((TreeViewItem)Owner).IsSelected = true;
}
///
/// Unselects this item.
///
void ISelectionItemProvider.RemoveFromSelection()
{
((TreeViewItem)Owner).IsSelected = false;
}
///
/// Returns whether the item is selected.
///
bool ISelectionItemProvider.IsSelected
{
get
{
return ((TreeViewItem)Owner).IsSelected;
}
}
///
/// The logical element that supports the SelectionPattern for this item.
///
IRawElementProviderSimple ISelectionItemProvider.SelectionContainer
{
get
{
ItemsControl parent = ((TreeViewItem)Owner).ParentItemsControl;
if (parent != null)
{
AutomationPeer peer = UIElementAutomationPeer.FromElement(parent);
if (peer != null)
return ProviderFromPeer(peer);
}
return null;
}
}
void IScrollItemProvider.ScrollIntoView()
{
((TreeViewItem)Owner).BringIntoView();
}
//
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
internal void RaiseAutomationIsSelectedChanged(bool isSelected)
{
RaisePropertyChangedEvent(
SelectionItemPatternIdentifiers.IsSelectedProperty,
!isSelected,
isSelected);
}
#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
- TransformerInfoCollection.cs
- Cursor.cs
- PriorityBinding.cs
- ToolStripDesignerAvailabilityAttribute.cs
- HostProtectionException.cs
- EdmProperty.cs
- ParenthesizePropertyNameAttribute.cs
- WindowsTitleBar.cs
- SerializationBinder.cs
- UnknownBitmapEncoder.cs
- XPathItem.cs
- CollectionViewGroupInternal.cs
- NameTable.cs
- ConfigurationElementCollection.cs
- ExpressionsCollectionConverter.cs
- FixedPage.cs
- SQLRoleProvider.cs
- LinkLabelLinkClickedEvent.cs
- BooleanSwitch.cs
- XmlDictionaryWriter.cs
- WebPartMinimizeVerb.cs
- WCFBuildProvider.cs
- GrammarBuilderBase.cs
- PackagePart.cs
- PropertyBuilder.cs
- WindowsListViewScroll.cs
- HttpResponse.cs
- FreezableDefaultValueFactory.cs
- HandlerElementCollection.cs
- TextDpi.cs
- OSFeature.cs
- AttributeUsageAttribute.cs
- ViewRendering.cs
- KnownBoxes.cs
- TemplateApplicationHelper.cs
- XmlSerializerSection.cs
- XPathMessageFilterTable.cs
- SubordinateTransaction.cs
- DiscoveryCallbackBehavior.cs
- HttpModulesInstallComponent.cs
- WinFormsSpinner.cs
- ManagementBaseObject.cs
- XmlSchemaRedefine.cs
- HorizontalAlignConverter.cs
- MimeTypePropertyAttribute.cs
- DoubleAnimationBase.cs
- ClientScriptItem.cs
- ConnectionInterfaceCollection.cs
- ColumnMapProcessor.cs
- EdmEntityTypeAttribute.cs
- Int16Converter.cs
- BitmapPalettes.cs
- TCEAdapterGenerator.cs
- IsolatedStoragePermission.cs
- SqlLiftIndependentRowExpressions.cs
- EntitySetBase.cs
- ModelItemDictionary.cs
- ListParaClient.cs
- CryptographicAttribute.cs
- GatewayDefinition.cs
- ProtocolsSection.cs
- MessageEnumerator.cs
- Stylus.cs
- ParserOptions.cs
- HitTestWithPointDrawingContextWalker.cs
- ApplicationContext.cs
- PointConverter.cs
- sqlcontext.cs
- DataTableClearEvent.cs
- ToolStripDropDown.cs
- ContourSegment.cs
- MenuItemStyle.cs
- AspProxy.cs
- CollectionDataContractAttribute.cs
- AppDomainManager.cs
- DataBinding.cs
- DateTimeHelper.cs
- Misc.cs
- EntityContainerEmitter.cs
- UpdateTracker.cs
- GroupedContextMenuStrip.cs
- HtmlInputHidden.cs
- MimeObjectFactory.cs
- DecoratedNameAttribute.cs
- ControlSerializer.cs
- CachedFontFamily.cs
- MenuItem.cs
- RuntimeHelpers.cs
- EventMappingSettings.cs
- CapabilitiesUse.cs
- ICspAsymmetricAlgorithm.cs
- GeometryValueSerializer.cs
- KeyedCollection.cs
- Animatable.cs
- WebHttpDispatchOperationSelectorData.cs
- DataReaderContainer.cs
- GeometryCollection.cs
- InternalConfigConfigurationFactory.cs
- SqlMultiplexer.cs
- XmlC14NWriter.cs