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.
コード例 #1
0
        /// <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);
        }
コード例 #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;
            }
        }
コード例 #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();
            }
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <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);
        }
コード例 #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;
        }
コード例 #7
0
		/// <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();
		}
コード例 #8
0
ファイル: AutoCompleteBox.cs プロジェクト: Kinnara/WPToolkit
        /// <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();
        }
コード例 #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);
 }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimePickerPopup"/> class.
 /// </summary>
 protected TimePickerPopup()
 {
     _timeCoercionHelper = new TimeCoercionHelper(this);
     _interaction        = new InteractionHelper(this);
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the Spinner class.
 /// </summary>
 protected Spinner()
 {
     Interaction = new InteractionHelper(this);
 }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the NumericUpDown class.
 /// </summary>
 public NumericUpDown() : base()
 {
     DefaultStyleKey = typeof(NumericUpDown);
     Interaction     = new InteractionHelper(this);
 }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the UpDownBase class.
 /// </summary>
 internal UpDownBase()
 {
     DefaultStyleKey = typeof(UpDownBase);
     Interaction     = new InteractionHelper(this);
 }
コード例 #15
0
        /// <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);
        }
コード例 #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;
            }
        }
コード例 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TimePickerPopup"/> class.
 /// </summary>
 protected TimePickerPopup()
 {
     _timeCoercionHelper = new TimeCoercionHelper(this);
     _interaction = new InteractionHelper(this);
 }
コード例 #18
0
 /// <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);
 }
コード例 #19
0
ファイル: RatingItem.cs プロジェクト: watchick/WpfToolkit
 /// <summary>
 /// Initializes a new instance of the RatingItem class.
 /// </summary>
 public RatingItem()
 {
     _interactionHelper = new InteractionHelper(this);
 }
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the UpDownBase class.
 /// </summary>
 internal UpDownBase() 
 {
     DefaultStyleKey = typeof(UpDownBase);
     Interaction = new InteractionHelper(this);
 }
コード例 #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();
        }
コード例 #22
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);
 }
コード例 #23
0
        /// <summary>
        /// Initializes a new instance of the RatingItem class.
        /// </summary>
        public RatingItem()
        {
#if SILVERLIGHT
            this.DefaultStyleKey = typeof(RatingItem);
#endif
            _interactionHelper = new InteractionHelper(this);
        }
コード例 #24
0
 /// <summary>
 /// Initializes a new instance of the Spinner class.
 /// </summary>
 protected Spinner()
 {
     Interaction = new InteractionHelper(this);
 }
コード例 #25
0
 /// <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);
 }
コード例 #26
0
ファイル: AutoCompleteBox.cs プロジェクト: 5nophilwu/S1Nyan
        /// <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();
        }
コード例 #27
0
 /// <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);
 }