Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / System / Windows / Controls / GridView.cs / 1 / GridView.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System.ComponentModel; // DesignerSerializationVisibility using System.Windows.Automation.Peers; using System.Windows.Markup; using System.Diagnostics; // Debug using MS.Internal; // Helper using MS.Internal.KnownBoxes; namespace System.Windows.Controls { ////// GridView is a built-in view of the ListView control. It is unique /// from other built-in views because of its table-like layout. Data in /// details view is shown in a table with each row corresponding to an /// entity in the data collection and each column being generated from a /// data-bound template, populated with values from the bound data entity. /// [StyleTypedProperty(Property = "ColumnHeaderContainerStyle", StyleTargetType = typeof(System.Windows.Controls.GridViewColumnHeader))] [ContentProperty("Columns")] public class GridView : ViewBase, IAddChild { //------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------- //-------------------------------------------------------------------- // // Public Methods // //------------------------------------------------------------------- #region Public Methods ////// Add an object child to this control /// void IAddChild.AddChild(object column) { AddChild(column); } ////// Add an object child to this control /// protected virtual void AddChild(object column) { GridViewColumn c = column as GridViewColumn; if (c != null) { Columns.Add(c); } else { throw new InvalidOperationException(SR.Get(SRID.ListView_IllegalChildrenType)); } } ////// Add a text string to this control /// void IAddChild.AddText(string text) { AddText(text); } ////// Add a text string to this control /// protected virtual void AddText(string text) { AddChild(text); } ////// Returns a string representation of this object. /// ///public override string ToString() { return SR.Get(SRID.ToStringFormatString_GridView, this.GetType(), Columns.Count); } /// /// called when ListView creates its Automation peer /// GridView override this method to return a GridViewAutomationPeer /// /// listview reference ///GridView automation peer internal protected override IViewAutomationPeer GetAutomationPeer(ListView parent) { return new GridViewAutomationPeer(this, parent); } #endregion //-------------------------------------------------------------------- // // Public Properties // //-------------------------------------------------------------------- #region Public Properties // For all the DPs on GridView, null is treated as unset, // because it's impossible to distinguish null and unset. // Change a property between null and unset, PropertyChangedCallback will not be called. // --------------------------------------------------------------------------- // Defines the names of the resources to be consumed by the GridView style. // Used to restyle several roles of GridView without having to restyle // all of the control. // ---------------------------------------------------------------------------- #region StyleKeys ////// Key used to mark the template of ScrollViewer for use by GridView /// public static ResourceKey GridViewScrollViewerStyleKey { get { if (_scrollViewerStyleKey == null) { _scrollViewerStyleKey = new SystemThemeKey(SystemResourceKeyID.GridViewScrollViewerStyle); } return _scrollViewerStyleKey; } } private static SystemThemeKey _scrollViewerStyleKey; ////// Key used to mark the Style of GridView /// public static ResourceKey GridViewStyleKey { get { if (_gridViewStyleKey == null) { _gridViewStyleKey = new SystemThemeKey(SystemResourceKeyID.GridViewStyle); } return _gridViewStyleKey; } } private static SystemThemeKey _gridViewStyleKey; ////// Key used to mark the Style of ItemContainer /// public static ResourceKey GridViewItemContainerStyleKey { get { if (_gridViewItemContainerStyleKey == null) { _gridViewItemContainerStyleKey = new SystemThemeKey(SystemResourceKeyID.GridViewItemContainerStyle); } return _gridViewItemContainerStyleKey; } } private static SystemThemeKey _gridViewItemContainerStyleKey; #endregion StyleKeys #region GridViewColumnCollection Attached DP ////// Reads the attached property GridViewColumnCollection from the given element. /// /// The element from which to read the GridViewColumnCollection attached property. ///The property's value. public static GridViewColumnCollection GetColumnCollection(DependencyObject element) { if (element == null) { throw new ArgumentNullException("element"); } return (GridViewColumnCollection)element.GetValue(ColumnCollectionProperty); } ////// Writes the attached property GridViewColumnCollection to the given element. /// /// The element to which to write the GridViewColumnCollection attached property. /// The collection to set public static void SetColumnCollection(DependencyObject element, GridViewColumnCollection collection) { if (element == null) { throw new ArgumentNullException("element"); } element.SetValue(ColumnCollectionProperty, collection); } ////// This is the dependency property registered for the GridView' ColumnCollection attached property. /// public static readonly DependencyProperty ColumnCollectionProperty = DependencyProperty.RegisterAttached( "ColumnCollection", typeof(GridViewColumnCollection), typeof(GridView)); ////// Whether should serialize ColumnCollection attach DP /// /// Object on which this DP is set [EditorBrowsable(EditorBrowsableState.Never)] public static bool ShouldSerializeColumnCollection(DependencyObject obj) { ListViewItem listViewItem = obj as ListViewItem; if (listViewItem != null) { ListView listView = listViewItem.ParentSelector as ListView; if (listView != null) { GridView gridView = listView.View as GridView; if (gridView != null) { // if GridViewColumnCollection attached on ListViewItem is Details.Columns, it should't be serialized. GridViewColumnCollection localValue = listViewItem.ReadLocalValue(ColumnCollectionProperty) as GridViewColumnCollection; return (localValue != gridView.Columns); } } } return true; } #endregion ///GridViewColumn List [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public GridViewColumnCollection Columns { get { if (_columns == null) { _columns = new GridViewColumnCollection(); // Give the collection a back-link, this is used for the inheritance context _columns.Owner = this; _columns.InViewMode = true; } return _columns; } } #region ColumnHeaderContainerStyle ////// ColumnHeaderContainerStyleProperty DependencyProperty /// public static readonly DependencyProperty ColumnHeaderContainerStyleProperty = DependencyProperty.Register( "ColumnHeaderContainerStyle", typeof(Style), typeof(GridView) ); ////// header container's style /// public Style ColumnHeaderContainerStyle { get { return (Style)GetValue(ColumnHeaderContainerStyleProperty); } set { SetValue(ColumnHeaderContainerStyleProperty, value); } } #endregion // ColumnHeaderContainerStyle #region ColumnHeaderTemplate ////// ColumnHeaderTemplate DependencyProperty /// public static readonly DependencyProperty ColumnHeaderTemplateProperty = DependencyProperty.Register( "ColumnHeaderTemplate", typeof(DataTemplate), typeof(GridView), new FrameworkPropertyMetadata( new PropertyChangedCallback(OnColumnHeaderTemplateChanged)) ); ////// column header template /// public DataTemplate ColumnHeaderTemplate { get { return (DataTemplate)GetValue(ColumnHeaderTemplateProperty); } set { SetValue(ColumnHeaderTemplateProperty, value); } } private static void OnColumnHeaderTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { GridView dv = (GridView)d; // Check to prevent Template and TemplateSelector at the same time Helper.CheckTemplateAndTemplateSelector("GridViewColumnHeader", ColumnHeaderTemplateProperty, ColumnHeaderTemplateSelectorProperty, dv); } #endregion ColumnHeaderTemplate #region ColumnHeaderTemplateSelector ////// ColumnHeaderTemplateSelector DependencyProperty /// public static readonly DependencyProperty ColumnHeaderTemplateSelectorProperty = DependencyProperty.Register( "ColumnHeaderTemplateSelector", typeof(DataTemplateSelector), typeof(GridView), new FrameworkPropertyMetadata( new PropertyChangedCallback(OnColumnHeaderTemplateSelectorChanged)) ); ////// header template selector /// ////// This property is ignored if [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public DataTemplateSelector ColumnHeaderTemplateSelector { get { return (DataTemplateSelector)GetValue(ColumnHeaderTemplateSelectorProperty); } set { SetValue(ColumnHeaderTemplateSelectorProperty, value); } } private static void OnColumnHeaderTemplateSelectorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { GridView dv = (GridView)d; // Check to prevent Template and TemplateSelector at the same time Helper.CheckTemplateAndTemplateSelector("GridViewColumnHeader", ColumnHeaderTemplateProperty, ColumnHeaderTemplateSelectorProperty, dv); } #endregion ColumnHeaderTemplateSelector #region AllowsColumnReorder ///is set. /// /// AllowsColumnReorderProperty DependencyProperty /// public static readonly DependencyProperty AllowsColumnReorderProperty = DependencyProperty.Register( "AllowsColumnReorder", typeof(bool), typeof(GridView), new FrameworkPropertyMetadata(BooleanBoxes.TrueBox /* default value */ ) ); ////// AllowsColumnReorder /// public bool AllowsColumnReorder { get { return (bool)GetValue(AllowsColumnReorderProperty); } set { SetValue(AllowsColumnReorderProperty, value); } } #endregion AllowsColumnReorder #region ColumnHeaderContextMenu ////// ColumnHeaderContextMenuProperty DependencyProperty /// public static readonly DependencyProperty ColumnHeaderContextMenuProperty = DependencyProperty.Register( "ColumnHeaderContextMenu", typeof(ContextMenu), typeof(GridView) ); ////// ColumnHeaderContextMenu /// public ContextMenu ColumnHeaderContextMenu { get { return (ContextMenu)GetValue(ColumnHeaderContextMenuProperty); } set { SetValue(ColumnHeaderContextMenuProperty, value); } } #endregion ColumnHeaderContextMenu #region ColumnHeaderToolTip ////// ColumnHeaderToolTipProperty DependencyProperty /// public static readonly DependencyProperty ColumnHeaderToolTipProperty = DependencyProperty.Register( "ColumnHeaderToolTip", typeof(object), typeof(GridView) ); ////// ColumnHeaderToolTip /// public object ColumnHeaderToolTip { get { return GetValue(ColumnHeaderToolTipProperty); } set { SetValue(ColumnHeaderToolTipProperty, value); } } #endregion ColumnHeaderToolTip #endregion // Public Properties //------------------------------------------------------------------- // // Protected Methods // //------------------------------------------------------------------- #region Protected Methods ////// called when ListView is prepare container for item. /// GridView override this method to attache the column collection /// /// the container protected internal override void PrepareItem(ListViewItem item) { base.PrepareItem(item); // attach GridViewColumnCollection to ListViewItem. SetColumnCollection(item, _columns); } ////// called when ListView is clear container for item. /// GridView override this method to clear the column collection /// /// the container protected internal override void ClearItem(ListViewItem item) { item.ClearValue(ColumnCollectionProperty); base.ClearItem(item); } #endregion //------------------------------------------------------------------- // // Protected Properties // //-------------------------------------------------------------------- #region Protected Properties ////// override with style key of GridView. /// protected internal override object DefaultStyleKey { get { return GridViewStyleKey; } } ////// override with style key using GridViewRowPresenter. /// protected internal override object ItemContainerDefaultStyleKey { get { return GridViewItemContainerStyleKey; } } #endregion //------------------------------------------------------------------- // // Internal Methods // //-------------------------------------------------------------------- #region Internal Methods internal override void OnInheritanceContextChangedCore(EventArgs args) { base.OnInheritanceContextChangedCore(args); if (_columns != null) { foreach (GridViewColumn column in _columns) { column.OnInheritanceContextChanged(args); } } } // Propagate theme changes to contained headers internal override void OnThemeChanged() { if (_columns != null) { for (int i=0; i<_columns.Count; i++) { _columns[i].OnThemeChanged(); } } } #endregion //-------------------------------------------------------------------- // // Private Fields // //------------------------------------------------------------------- #region Private Fields private GridViewColumnCollection _columns; #endregion // Private Fields internal GridViewHeaderRowPresenter HeaderRowPresenter { get { return _gvheaderRP; } set { _gvheaderRP = value; } } private GridViewHeaderRowPresenter _gvheaderRP; } } // 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
- ReferenceEqualityComparer.cs
- PersonalizationEntry.cs
- CodeDirectiveCollection.cs
- PseudoWebRequest.cs
- ConsoleKeyInfo.cs
- DesignerAdRotatorAdapter.cs
- List.cs
- CommandValueSerializer.cs
- XmlEncoding.cs
- CodeTypeParameter.cs
- SafeEventLogWriteHandle.cs
- UserValidatedEventArgs.cs
- COM2PropertyPageUITypeConverter.cs
- WSDualHttpBindingCollectionElement.cs
- StorageMappingItemLoader.cs
- WebSysDisplayNameAttribute.cs
- AutomationTextAttribute.cs
- TCEAdapterGenerator.cs
- GridViewItemAutomationPeer.cs
- TargetException.cs
- SqlUserDefinedTypeAttribute.cs
- LocalizableResourceBuilder.cs
- TrustManagerMoreInformation.cs
- XPathNavigatorKeyComparer.cs
- ToolStripRenderEventArgs.cs
- RotateTransform3D.cs
- CheckPair.cs
- ButtonBaseAutomationPeer.cs
- PrinterResolution.cs
- MemberAccessException.cs
- MiniMapControl.xaml.cs
- OracleInfoMessageEventArgs.cs
- TreeViewItemAutomationPeer.cs
- DataListItem.cs
- ConnectionInterfaceCollection.cs
- ConfigurationElementCollection.cs
- DataGridToolTip.cs
- Parser.cs
- MetadataUtilsSmi.cs
- ItemTypeToolStripMenuItem.cs
- TextServicesCompartment.cs
- ColumnMapCopier.cs
- BatchParser.cs
- ProviderException.cs
- ScriptReference.cs
- CommonObjectSecurity.cs
- DesigntimeLicenseContext.cs
- RuntimeConfig.cs
- CodeTypeDelegate.cs
- HttpDebugHandler.cs
- PerspectiveCamera.cs
- AndCondition.cs
- KeyNotFoundException.cs
- LinkButton.cs
- SkipStoryboardToFill.cs
- XmlNodeList.cs
- AdapterDictionary.cs
- DocumentPageHost.cs
- RequestCacheEntry.cs
- ResourcePool.cs
- AmbientProperties.cs
- RemoteTokenFactory.cs
- LoginNameDesigner.cs
- ThousandthOfEmRealDoubles.cs
- xmlfixedPageInfo.cs
- SQLDoubleStorage.cs
- MenuRendererClassic.cs
- CacheVirtualItemsEvent.cs
- ThicknessAnimationBase.cs
- SettingsPropertyValueCollection.cs
- PageAsyncTaskManager.cs
- ApplicationHost.cs
- DiffuseMaterial.cs
- IntegerValidatorAttribute.cs
- Root.cs
- HandlerMappingMemo.cs
- TraceShell.cs
- GeometryHitTestResult.cs
- WebPartAuthorizationEventArgs.cs
- AddInPipelineAttributes.cs
- TreeNodeCollectionEditorDialog.cs
- TableStyle.cs
- MissingMemberException.cs
- Module.cs
- ArrayElementGridEntry.cs
- DeviceFilterDictionary.cs
- LaxModeSecurityHeaderElementInferenceEngine.cs
- RouteTable.cs
- GeneralTransformGroup.cs
- ObfuscateAssemblyAttribute.cs
- Padding.cs
- GeometryModel3D.cs
- DesignerLinkAdapter.cs
- SmiContext.cs
- StickyNoteHelper.cs
- DictionaryKeyPropertyAttribute.cs
- XmlEntityReference.cs
- EventRouteFactory.cs
- InputLanguageSource.cs
- ReadOnlyObservableCollection.cs