The InteractionHelper provides controls with support for all of the common interactions like mouse movement, mouse clicks, key presses, etc., and also incorporates proper event semantics when the control is disabled.
        /// <summary>
        /// Initializes a new instance of the AccordionItem class.
        /// </summary>
        public AccordionItem()
        {
            // initialize to no action.
            ScheduledAction = AccordionAction.None;

#if SILVERLIGHT
            DefaultStyleKey = typeof(AccordionItem);
#endif
            _interaction = new InteractionHelper(this);
        }
Example #2
0
        /// <summary>
        /// Provides handling for the
        /// <see cref="E:System.Windows.UIElement.KeyDown" /> event.
        /// </summary>
        /// <param name="e">Key event args.</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Handled || !IsEnabled)
            {
                return;
            }

            // Some keys (e.g. Left/Right) need to be translated in RightToLeft mode
            Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, e.Key);

            bool isExpanded = IsExpanded;

            switch (ExpandDirection)
            {
            case ExpandDirection.Down:
                if ((isExpanded && invariantKey == Key.Up) || (!isExpanded && invariantKey == Key.Down))
                {
                    IsExpanded = !isExpanded;
                }
                break;

            case ExpandDirection.Up:
                if ((isExpanded && invariantKey == Key.Down) || (!isExpanded && invariantKey == Key.Up))
                {
                    IsExpanded = !isExpanded;
                }
                break;

            case ExpandDirection.Left:
                if ((isExpanded && invariantKey == Key.Right) || (!isExpanded && invariantKey == Key.Left))
                {
                    IsExpanded = !isExpanded;
                }
                break;

            case ExpandDirection.Right:
                if ((isExpanded && invariantKey == Key.Left) || (!isExpanded && invariantKey == Key.Right))
                {
                    IsExpanded = !isExpanded;
                }
                break;
            }
        }
Example #3
0
        /// <summary>
        /// This is the method that responds to the KeyDown event.
        /// </summary>
        /// <param name="e">
        /// A <see cref="T:System.Windows.Input.KeyEventArgs" /> that contains
        /// the event data.
        /// </param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (e.Handled)
            {
                return;
            }

            // Some keys (e.g. Left/Right) need to be translated in RightToLeft mode
            Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, e.Key);

            TabItem nextTabItem = null;

            int direction  = 0;
            int startIndex = TabControlParent.Items.IndexOf(this);

            switch (invariantKey)
            {
            case Key.Right:
            case Key.Down:
                direction = 1;
                break;

            case Key.Left:
            case Key.Up:
                direction = -1;
                break;

            default:
                return;
            }

            nextTabItem = TabControlParent.FindNextTabItem(startIndex, direction);

            if (nextTabItem != null && nextTabItem != TabControlParent.SelectedItem)
            {
                e.Handled = true;
                TabControlParent.SelectedItem = nextTabItem;
                nextTabItem.Focus();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Accordion"/> class.
        /// </summary>
        public Accordion()
        {
#if SILVERLIGHT
            DefaultStyleKey = typeof(Accordion);
#endif
            ItemsControlHelper = new ItemsControlHelper(this);

            ObservableCollection<object> items = new ObservableCollection<object>();
            ObservableCollection<int> indices = new ObservableCollection<int>();

            SelectedItems = items;
            SelectedIndices = indices;

            items.CollectionChanged += OnSelectedItemsCollectionChanged;
            indices.CollectionChanged += OnSelectedIndicesCollectionChanged;

            _scheduledActions = new List<AccordionItem>();
            SizeChanged += OnAccordionSizeChanged;
            Interaction = new InteractionHelper(this);
        }
        /// <summary>
        /// Initialises a new instance of the AccordionItem class.
        /// </summary>
        public AccordionItem()
        {
            // initialize to no action.
            this.ScheduledAction = AccordionAction.None;

            this.interaction = new InteractionHelper(this);
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Picker"/> class.
        /// </summary>
        protected Picker()
        {
            DefaultStyleKey = typeof(Picker);
            Interaction = new InteractionHelper(this);

            IsEnabledChanged += ControlIsEnabledChanged;
        }
		/// <summary>  
		/// Initializes a new instance of the  
		/// <see cref="T:Microsoft.Phone.Controls.AutoCompleteBox" /> class.  
		/// </summary>  
		public AutoCompleteBox()
		{
			DefaultStyleKey = typeof(AutoCompleteBox);

			Loaded += WorkAroundApplyTemplate;
#if WINDOWS_PHONE
			Loaded += WorkAroundHookupOrientationChanged;
#endif
			IsEnabledChanged += ControlIsEnabledChanged;

			Interaction = new InteractionHelper(this);

			// Creating the view here ensures that View is always != null  
			ClearView();
		}
Example #8
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="T:Microsoft.Phone.Controls.AutoCompleteBox" /> class.
        /// </summary>
        public AutoCompleteBox()
        {
            DefaultStyleKey = typeof(AutoCompleteBox);

            Loaded += OnLoaded;
            Unloaded += OnUnloaded;

            IsEnabledChanged += ControlIsEnabledChanged;

            Interaction = new InteractionHelper(this);

            // Creating the view here ensures that View is always != null
            ClearView();
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Controls.Expander" /> class.
 /// </summary>
 public Expander()
 {
     DefaultStyleKey = typeof(Expander);
     Interaction     = new InteractionHelper(this);
 }
        /// <summary>
        /// Initializes a new instance of the AccordionItem class.
        /// </summary>
        public AccordionItem()
        {
            // initialize to no action.
            ScheduledAction = AccordionAction.None;

            DefaultStyleKey = typeof(AccordionItem);
            _interaction = new InteractionHelper(this);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TimePickerPopup"/> class.
 /// </summary>
 protected TimePickerPopup()
 {
     _timeCoercionHelper = new TimeCoercionHelper(this);
     _interaction        = new InteractionHelper(this);
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the Spinner class.
 /// </summary>
 protected Spinner()
 {
     Interaction = new InteractionHelper(this);
 }
 /// <summary>
 /// Initializes a new instance of the NumericUpDown class.
 /// </summary>
 public NumericUpDown() : base()
 {
     DefaultStyleKey = typeof(NumericUpDown);
     Interaction     = new InteractionHelper(this);
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the UpDownBase class.
 /// </summary>
 internal UpDownBase()
 {
     DefaultStyleKey = typeof(UpDownBase);
     Interaction     = new InteractionHelper(this);
 }
        /// <summary>
        /// Handle keys related to scrolling.
        /// </summary>
        /// <param name="key">The key to handle.</param>
        /// <returns>A value indicating whether the key was handled.</returns>
        private bool HandleScrollKeys(Key key)
        {
            ScrollViewer scrollHost = ItemsControlHelper.ScrollHost;

            if (scrollHost != null)
            {
                // Some keys (e.g. Left/Right) need to be translated in RightToLeft mode
                Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, key);

                switch (invariantKey)
                {
                case Key.PageUp:
                    // Move horizontally if we've run out of room vertically
                    if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageLeft();
                    }
                    else
                    {
                        scrollHost.PageUp();
                    }
                    return(true);

                case Key.PageDown:
                    // Move horizontally if we've run out of room vertically
                    if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight))
                    {
                        scrollHost.PageRight();
                    }
                    else
                    {
                        scrollHost.PageDown();
                    }
                    return(true);

                case Key.Home:
                    scrollHost.ScrollToTop();
                    return(true);

                case Key.End:
                    scrollHost.ScrollToBottom();
                    return(true);

                case Key.Left:
                    scrollHost.LineLeft();
                    return(true);

                case Key.Right:
                    scrollHost.LineRight();
                    return(true);

                case Key.Up:
                    scrollHost.LineUp();
                    return(true);

                case Key.Down:
                    scrollHost.LineDown();
                    return(true);
                }
            }
            return(false);
        }
Example #16
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (!Interaction.AllowKeyDown(e))
            {
                return;
            }

            base.OnKeyDown(e);

            if (e.Handled)
            {
                return;
            }

            // Some keys (e.g. Left/Right) need to be translated in RightToLeft mode
            Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, e.Key);

            switch (invariantKey)
            {
            case Key.Left:
            {
#if SILVERLIGHT
                RatingItem ratingItem = FocusManager.GetFocusedElement() as RatingItem;
#else
                RatingItem ratingItem = FocusManager.GetFocusedElement(Application.Current.MainWindow) as RatingItem;
#endif
                if (ratingItem != null)
                {
                    ratingItem = GetRatingItemAtOffsetFrom(ratingItem, -1);
                }
                else
                {
                    ratingItem = GetRatingItems().FirstOrDefault();
                }
                if (ratingItem != null)
                {
                    if (ratingItem.Focus())
                    {
                        e.Handled = true;
                    }
                }
            }
            break;

            case Key.Right:
            {
#if SILVERLIGHT
                RatingItem ratingItem = FocusManager.GetFocusedElement() as RatingItem;
#else
                RatingItem ratingItem = FocusManager.GetFocusedElement(Application.Current.MainWindow) as RatingItem;
#endif
                if (ratingItem != null)
                {
                    ratingItem = GetRatingItemAtOffsetFrom(ratingItem, 1);
                }
                else
                {
                    ratingItem = GetRatingItems().FirstOrDefault();
                }
                if (ratingItem != null)
                {
                    if (ratingItem.Focus())
                    {
                        e.Handled = true;
                    }
                }
            }
            break;

            case Key.Add:
            {
                if (!this.IsReadOnly)
                {
                    RatingItem ratingItem = GetSelectedRatingItem();
                    if (ratingItem != null)
                    {
                        ratingItem = GetRatingItemAtOffsetFrom(ratingItem, 1);
                    }
                    else
                    {
                        ratingItem = GetRatingItems().FirstOrDefault();
                    }
                    if (ratingItem != null)
                    {
                        ratingItem.SelectValue();
                        e.Handled = true;
                    }
                }
            }
            break;

            case Key.Subtract:
            {
                if (!this.IsReadOnly)
                {
                    RatingItem ratingItem = GetSelectedRatingItem();
                    if (ratingItem != null)
                    {
                        ratingItem = GetRatingItemAtOffsetFrom(ratingItem, -1);
                    }
                    if (ratingItem != null)
                    {
                        ratingItem.SelectValue();
                        e.Handled = true;
                    }
                }
            }
            break;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TimePickerPopup"/> class.
 /// </summary>
 protected TimePickerPopup()
 {
     _timeCoercionHelper = new TimeCoercionHelper(this);
     _interaction = new InteractionHelper(this);
 }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Controls.TreeView" /> class.
 /// </summary>
 public TreeView()
 {
     DefaultStyleKey    = typeof(TreeView);
     ItemsControlHelper = new ItemsControlHelper(this);
     Interaction        = new InteractionHelper(this);
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the RatingItem class.
 /// </summary>
 public RatingItem()
 {
     _interactionHelper = new InteractionHelper(this);
 }
 /// <summary>
 /// Initializes a new instance of the UpDownBase class.
 /// </summary>
 internal UpDownBase() 
 {
     DefaultStyleKey = typeof(UpDownBase);
     Interaction = new InteractionHelper(this);
 }
Example #21
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="T:System.Windows.Controls.AutoCompleteBox" /> class.
        /// </summary>
        public AutoCompleteBox()
        {
#if SILVERLIGHT  
            DefaultStyleKey = typeof(AutoCompleteBox);

            Loaded += (sender, e) => ApplyTemplate();
#endif
            IsEnabledChanged += ControlIsEnabledChanged;

            Interaction = new InteractionHelper(this);

            // Creating the view here ensures that View is always != null
            ClearView();
        }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Controls.Expander" /> class.
 /// </summary>
 public Expander()
 {
     DefaultStyleKey = typeof(Expander);
     Interaction = new InteractionHelper(this);
 }
        /// <summary>
        /// Initializes a new instance of the RatingItem class.
        /// </summary>
        public RatingItem()
        {
#if SILVERLIGHT
            this.DefaultStyleKey = typeof(RatingItem);
#endif
            _interactionHelper = new InteractionHelper(this);
        }
Example #24
0
 /// <summary>
 /// Initializes a new instance of the Spinner class.
 /// </summary>
 protected Spinner()
 {
     Interaction = new InteractionHelper(this);
 }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Controls.TreeView" /> class.
 /// </summary>
 public TreeView()
 {
     DefaultStyleKey = typeof(TreeView);
     ItemsControlHelper = new ItemsControlHelper(this);
     Interaction = new InteractionHelper(this);
 }
Example #26
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="T:Microsoft.Phone.Controls.AutoCompleteBox" /> class.
        /// </summary>
        public AutoCompleteBox()
        {
            DefaultStyleKey = typeof(AutoCompleteBox);

            Loaded += (sender, e) => ApplyTemplate();
#if WINDOWS_PHONE
            Loaded += delegate
            {
                PhoneApplicationFrame frame;
                if (PhoneHelper.TryGetPhoneApplicationFrame(out frame))
                {
                    frame.OrientationChanged += delegate
                    {
                        IsDropDownOpen = false;
                    };
                }
            };
#endif
            IsEnabledChanged += ControlIsEnabledChanged;

            Interaction = new InteractionHelper(this);

            // Creating the view here ensures that View is always != null
            ClearView();
        }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Controls.TreeViewItem" /> class.
 /// </summary>
 public TreeViewItem()
 {
     DefaultStyleKey = typeof(TreeViewItem);
     Interaction = new InteractionHelper(this);
 }