Code:
                         / Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / Controls / ComboBoxItem.cs / 1 / ComboBoxItem.cs
                        
                        
                            //---------------------------------------------------------------------------- 
//
// Copyright (C) Microsoft Corporation.  All rights reserved.
//
// File: ComboBoxItem.cs 
//
//--------------------------------------------------------------------------- 
using MS.Internal; 
using MS.Internal.KnownBoxes;
using System; 
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Threading; 
using System.Windows.Automation; 
using System.Windows.Automation.Provider; 
using System.Windows.Media;
using System.Windows.Input; 
using System.Windows.Controls.Primitives;
using System.Windows.Shapes;
namespace System.Windows.Controls 
{
    ///  
    ///     Control that implements a selectable item inside a ComboBox. 
    ///  
    [Localizability(LocalizationCategory.ComboBox)] 
#if OLD_AUTOMATION
    [Automation(AccessibilityControlType = "ListItem")]
#endif
    public class ComboBoxItem : ListBoxItem 
    {
        //------------------------------------------------------------------- 
        // 
        //  Constructors
        // 
        //-------------------------------------------------------------------
        #region Constructors
 
        /// 
        ///     Default DependencyObject constructor 
        ///   
        /// 
        ///     Automatic determination of current Dispatcher. Use alternative constructor 
        ///     that accepts a Dispatcher for best performance.
        ///  
        public ComboBoxItem() : base()
        { 
        }
 
        static ComboBoxItem() 
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ComboBoxItem), new FrameworkPropertyMetadata(typeof(ComboBoxItem))); 
            _dType = DependencyObjectType.FromSystemTypeInternal(typeof(ComboBoxItem));
        }
        #endregion 
        #region Public Properties 
 
        /// 
        ///     The key needed set a read-only property. 
        ///  
        private static readonly DependencyPropertyKey IsHighlightedPropertyKey =
            DependencyProperty.RegisterReadOnly("IsHighlighted", typeof(bool), typeof(ComboBoxItem),
                                        new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); 
        ///  
        /// DependencyProperty for the IsHighlighted property 
        ///  
        public static readonly DependencyProperty IsHighlightedProperty = 
            IsHighlightedPropertyKey.DependencyProperty;
        /// 
        /// Indicates if the item is highlighted or not.  Styles that want to 
        /// show a highlight for selection should trigger off of this value.
        ///   
        /// 
        ///     This is the method that responds to the MouseButtonEvent event. 
        ///  
        /// Event arguments 
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) 
        {
            e.Handled = true; 
            ComboBox parent = ParentComboBox;
            if (parent != null) 
            {
                parent.NotifyComboBoxItemMouseDown(this); 
            } 
            base.OnMouseLeftButtonDown(e); 
        }
        /// 
        /// 
        ///  
        ///  
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) 
        {
            e.Handled = true; 
            ComboBox parent = ParentComboBox;
            if (parent != null) 
            {
                parent.NotifyComboBoxItemMouseUp(this); 
            } 
            base.OnMouseLeftButtonUp(e); 
        }
        /// 
        /// 
        ///  
        ///  
        protected override void OnMouseEnter(MouseEventArgs e) 
        {
            e.Handled = true; 
            ComboBox parent = ParentComboBox;
            if (parent != null) 
            {
                parent.NotifyComboBoxItemEnter(this); 
            } 
            base.OnMouseEnter(e); 
        }
        ///  
        /// Called when Content property has been changed.
        ///   
        ///  
        /// 
        protected override void OnContentChanged(object oldContent, object newContent) 
        {
            base.OnContentChanged(oldContent, newContent);
            // If this is selected, we need to update ParentComboBox.Text 
            // Scenario:
            //       
            //          item1  
            //          Item2 
            //          item3  
            //       
            // In this case ComboBox will try to update Text property as soon as it get
            // SelectionChanged event. However, at that time ComboBoxItem.Content is not
            // parse yet. So, Content is null. This causes ComboBox.Text to be "". 
            //
            ComboBox parent; 
            if (IsSelected && (null != (parent = ParentComboBox))) 
            {
                parent.SelectedItemUpdated(); 
            }
            // When the content of the combobox item is a UIElement,
            // combobox will create a visual clone of the item which needs 
            // to update even when the combobox is closed
            SetFlags(newContent is UIElement, VisualFlags.IsLayoutIslandRoot); 
        } 
        ///  
        ///     Called when this element gets focus.
        ///  
        /// 
        protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e) 
        {
            e.Handled = true; 
 
            ComboBox parent = ParentComboBox;
 
            if (parent != null)
            {
                parent.NotifyComboBoxItemEnter(this);
            } 
            base.OnGotKeyboardFocus(e); 
        } 
        #endregion 
        //--------------------------------------------------------------------
        //
        //  Implementation 
        //
        //-------------------------------------------------------------------- 
 
        #region Implementation
 
        private ComboBox ParentComboBox
        {
            get
            { 
                return ParentSelector as ComboBox;
            } 
        } 
        internal void SetIsHighlighted(bool isHighlighted) 
        {
            IsHighlighted = isHighlighted;
        }
 
        #endregion
 
        #region DTypeThemeStyleKey 
        // Returns the DependencyObjectType for the registered ThemeStyleKey's default 
        // value. Controls will override this method to return approriate types.
        internal override DependencyObjectType DTypeThemeStyleKey
        {
            get { return _dType; } 
        }
 
        private static DependencyObjectType _dType; 
        #endregion DTypeThemeStyleKey 
    }
}
// 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.
//
// File: ComboBoxItem.cs 
//
//--------------------------------------------------------------------------- 
using MS.Internal; 
using MS.Internal.KnownBoxes;
using System; 
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Threading; 
using System.Windows.Automation; 
using System.Windows.Automation.Provider; 
using System.Windows.Media;
using System.Windows.Input; 
using System.Windows.Controls.Primitives;
using System.Windows.Shapes;
namespace System.Windows.Controls 
{
    ///  
    ///     Control that implements a selectable item inside a ComboBox. 
    ///  
    [Localizability(LocalizationCategory.ComboBox)] 
#if OLD_AUTOMATION
    [Automation(AccessibilityControlType = "ListItem")]
#endif
    public class ComboBoxItem : ListBoxItem 
    {
        //------------------------------------------------------------------- 
        // 
        //  Constructors
        // 
        //-------------------------------------------------------------------
        #region Constructors
 
        /// 
        ///     Default DependencyObject constructor 
        ///   
        /// 
        ///     Automatic determination of current Dispatcher. Use alternative constructor 
        ///     that accepts a Dispatcher for best performance.
        ///  
        public ComboBoxItem() : base()
        { 
        }
 
        static ComboBoxItem() 
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ComboBoxItem), new FrameworkPropertyMetadata(typeof(ComboBoxItem))); 
            _dType = DependencyObjectType.FromSystemTypeInternal(typeof(ComboBoxItem));
        }
        #endregion 
        #region Public Properties 
 
        /// 
        ///     The key needed set a read-only property. 
        ///  
        private static readonly DependencyPropertyKey IsHighlightedPropertyKey =
            DependencyProperty.RegisterReadOnly("IsHighlighted", typeof(bool), typeof(ComboBoxItem),
                                        new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); 
        ///  
        /// DependencyProperty for the IsHighlighted property 
        ///  
        public static readonly DependencyProperty IsHighlightedProperty = 
            IsHighlightedPropertyKey.DependencyProperty;
        /// 
        /// Indicates if the item is highlighted or not.  Styles that want to 
        /// show a highlight for selection should trigger off of this value.
        ///   
        /// 
        ///     This is the method that responds to the MouseButtonEvent event. 
        ///  
        /// Event arguments 
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) 
        {
            e.Handled = true; 
            ComboBox parent = ParentComboBox;
            if (parent != null) 
            {
                parent.NotifyComboBoxItemMouseDown(this); 
            } 
            base.OnMouseLeftButtonDown(e); 
        }
        /// 
        /// 
        ///  
        ///  
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) 
        {
            e.Handled = true; 
            ComboBox parent = ParentComboBox;
            if (parent != null) 
            {
                parent.NotifyComboBoxItemMouseUp(this); 
            } 
            base.OnMouseLeftButtonUp(e); 
        }
        /// 
        /// 
        ///  
        ///  
        protected override void OnMouseEnter(MouseEventArgs e) 
        {
            e.Handled = true; 
            ComboBox parent = ParentComboBox;
            if (parent != null) 
            {
                parent.NotifyComboBoxItemEnter(this); 
            } 
            base.OnMouseEnter(e); 
        }
        ///  
        /// Called when Content property has been changed.
        ///   
        ///  
        /// 
        protected override void OnContentChanged(object oldContent, object newContent) 
        {
            base.OnContentChanged(oldContent, newContent);
            // If this is selected, we need to update ParentComboBox.Text 
            // Scenario:
            //       
            //          item1  
            //          Item2 
            //          item3  
            //       
            // In this case ComboBox will try to update Text property as soon as it get
            // SelectionChanged event. However, at that time ComboBoxItem.Content is not
            // parse yet. So, Content is null. This causes ComboBox.Text to be "". 
            //
            ComboBox parent; 
            if (IsSelected && (null != (parent = ParentComboBox))) 
            {
                parent.SelectedItemUpdated(); 
            }
            // When the content of the combobox item is a UIElement,
            // combobox will create a visual clone of the item which needs 
            // to update even when the combobox is closed
            SetFlags(newContent is UIElement, VisualFlags.IsLayoutIslandRoot); 
        } 
        ///  
        ///     Called when this element gets focus.
        ///  
        /// 
        protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e) 
        {
            e.Handled = true; 
 
            ComboBox parent = ParentComboBox;
 
            if (parent != null)
            {
                parent.NotifyComboBoxItemEnter(this);
            } 
            base.OnGotKeyboardFocus(e); 
        } 
        #endregion 
        //--------------------------------------------------------------------
        //
        //  Implementation 
        //
        //-------------------------------------------------------------------- 
 
        #region Implementation
 
        private ComboBox ParentComboBox
        {
            get
            { 
                return ParentSelector as ComboBox;
            } 
        } 
        internal void SetIsHighlighted(bool isHighlighted) 
        {
            IsHighlighted = isHighlighted;
        }
 
        #endregion
 
        #region DTypeThemeStyleKey 
        // Returns the DependencyObjectType for the registered ThemeStyleKey's default 
        // value. Controls will override this method to return approriate types.
        internal override DependencyObjectType DTypeThemeStyleKey
        {
            get { return _dType; } 
        }
 
        private static DependencyObjectType _dType; 
        #endregion DTypeThemeStyleKey 
    }
}
// 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
- Int32RectValueSerializer.cs
- SiteMapNodeItem.cs
- Hex.cs
- CookieParameter.cs
- EntityDataSourceDataSelectionPanel.cs
- AnnotationHighlightLayer.cs
- TPLETWProvider.cs
- QueryContinueDragEvent.cs
- FormViewPagerRow.cs
- XmlBinaryReaderSession.cs
- PartBasedPackageProperties.cs
- BamlTreeMap.cs
- LambdaCompiler.Unary.cs
- TextServicesManager.cs
- ObjectViewListener.cs
- SecurityTokenSerializer.cs
- ParameterReplacerVisitor.cs
- Configuration.cs
- KeyInfo.cs
- SingleBodyParameterMessageFormatter.cs
- DetailsViewDeletedEventArgs.cs
- ArgumentNullException.cs
- SelectionRangeConverter.cs
- DataFieldConverter.cs
- Transactions.cs
- SiteMapSection.cs
- NameValueCollection.cs
- ProxyWebPart.cs
- OracleCommand.cs
- Mappings.cs
- ReturnEventArgs.cs
- MobileCategoryAttribute.cs
- _NetworkingPerfCounters.cs
- FixedStringLookup.cs
- VectorCollectionConverter.cs
- Exception.cs
- StatusBarDrawItemEvent.cs
- SafeHandles.cs
- figurelengthconverter.cs
- Column.cs
- QilIterator.cs
- SignedInfo.cs
- FrameAutomationPeer.cs
- BrushConverter.cs
- RegularExpressionValidator.cs
- QilFactory.cs
- ManagementOptions.cs
- SqlNode.cs
- DataGridSortCommandEventArgs.cs
- ControlSerializer.cs
- SmiTypedGetterSetter.cs
- NamespaceImport.cs
- Int32Collection.cs
- RowBinding.cs
- XmlConverter.cs
- ParameterInfo.cs
- DetailsViewPagerRow.cs
- XmlCharacterData.cs
- RouteItem.cs
- DesignerSerializerAttribute.cs
- BooleanFunctions.cs
- AddInIpcChannel.cs
- EventDescriptor.cs
- Wrapper.cs
- StylusCaptureWithinProperty.cs
- MinMaxParagraphWidth.cs
- BigInt.cs
- XPathSelfQuery.cs
- GridViewSortEventArgs.cs
- RadioButtonFlatAdapter.cs
- IndentedWriter.cs
- ConversionContext.cs
- ObjectStateManager.cs
- Propagator.Evaluator.cs
- sqlstateclientmanager.cs
- CodeObject.cs
- regiisutil.cs
- InternalConfigHost.cs
- UriExt.cs
- SettingsSavedEventArgs.cs
- TransactionalPackage.cs
- RealProxy.cs
- CodeArrayCreateExpression.cs
- DiscoveryExceptionDictionary.cs
- OpenTypeLayoutCache.cs
- AdRotatorDesigner.cs
- ExpressionBindingCollection.cs
- RsaKeyGen.cs
- HitTestDrawingContextWalker.cs
- DataGridViewCellConverter.cs
- ListViewTableRow.cs
- WeakReadOnlyCollection.cs
- TemplatedControlDesigner.cs
- BindingContext.cs
- RandomDelayQueuedSendsAsyncResult.cs
- ColorConverter.cs
- LineInfo.cs
- InfoCardProofToken.cs
- EdmScalarPropertyAttribute.cs
- DataContext.cs