Ejemplo n.º 1
0
        public virtual void NumericUpDownPeerSupportsRangeValueAndValue()
        {
            NumericUpDown item = new NumericUpDown();
            NumericUpDownAutomationPeer peer = null;

            TestAsync(
                item,
                () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(item) as NumericUpDownAutomationPeer,
                () => Assert.IsNull(peer.GetPattern(PatternInterface.Dock), "NumericUpDownAutomationPeer should not support the Dock pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.ExpandCollapse), "NumericUpDownAutomationPeer should not support the ExpandCollapse pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.Grid), "NumericUpDownAutomationPeer should not support the Grid pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.GridItem), "NumericUpDownAutomationPeer should not support the GridItem pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.Invoke), "NumericUpDownAutomationPeer should not support the Dock pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.MultipleView), "NumericUpDownAutomationPeer should not support the MultipleView pattern!"),
                () => Assert.IsNotNull(peer.GetPattern(PatternInterface.RangeValue), "NumericUpDownAutomationPeer should support the RangeValue pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.Scroll), "NumericUpDownAutomationPeer should not support the Scroll pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.ScrollItem), "NumericUpDownAutomationPeer should not support the ScrollItem pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.Selection), "NumericUpDownAutomationPeer should not support the Selection pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.Table), "NumericUpDownAutomationPeer should not support the Table pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.TableItem), "NumericUpDownAutomationPeer should not support the TableItem pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.Toggle), "NumericUpDownAutomationPeer should not support the Toggle pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.Transform), "NumericUpDownAutomationPeer should not support the Transform pattern!"),
                () => Assert.IsNotNull(peer.GetPattern(PatternInterface.Value), "NumericUpDownAutomationPeer should support the Value pattern!"),
                () => Assert.IsNull(peer.GetPattern(PatternInterface.Window), "NumericUpDownAutomationPeer should not support the Window pattern!"));
        }
Ejemplo n.º 2
0
        public virtual void NumericUpDownAutomationPeerTypeAndClass()
        {
            NumericUpDown item = new NumericUpDown();
            NumericUpDownAutomationPeer peer = null;

            TestAsync(
                item,
                () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(item) as NumericUpDownAutomationPeer,
                () => Assert.AreEqual(AutomationControlType.Spinner, peer.GetAutomationControlType(), "Unexpected AutomationControlType!"),
                () => Assert.AreEqual("NumericUpDown", peer.GetClassName(), "Unexpected ClassType!"));
        }
Ejemplo n.º 3
0
        public virtual void NumericUpDownCreatesAutomationPeer()
        {
            NumericUpDown item = new NumericUpDown();
            NumericUpDownAutomationPeer peer = null;

            TestAsync(
                item,
                () => peer = FrameworkElementAutomationPeer.CreatePeerForElement(item) as NumericUpDownAutomationPeer,
                () => Assert.IsNotNull(peer, "NumericUpDown peer should not be null!"),
                () => Assert.AreEqual(item, peer.Owner, "NumericUpDown should be owner of the peer!"));
        }
Ejemplo n.º 4
0
        public virtual void NumericUpDownPeerSupportsRangeValue()
        {
            NumericUpDown item = new NumericUpDown();
            NumericUpDownAutomationPeer peer     = null;
            IRangeValueProvider         provider = null;

            TestAsync(
                item,
                () => peer     = FrameworkElementAutomationPeer.CreatePeerForElement(item) as NumericUpDownAutomationPeer,
                () => provider = peer.GetPattern(PatternInterface.RangeValue) as IRangeValueProvider,
                () => Assert.IsNotNull(provider, "IRangeValueProvider peer should not be null!"));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Override UpDownBase&lt;T&gt;.OnValueChanged to raise value changed automation event and
        /// determine if a maximum or minimum has been reached.
        /// </summary>
        /// <param name="e">Event args.</param>
        protected override void OnValueChanged(RoutedPropertyChangedEventArgs <double> e)
        {
            NumericUpDownAutomationPeer peer = FrameworkElementAutomationPeer.FromElement(this) as NumericUpDownAutomationPeer;

            if (peer != null)
            {
                peer.RaisePropertyChangedEvent(RangeValuePatternIdentifiers.ValueProperty, e.OldValue, e.NewValue);
            }

            // reevaluate the valid spin direction
            SetValidSpinDirection();

            base.OnValueChanged(e);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// IncrementProperty property changed handler.
        /// </summary>
        /// <param name="d">NumericUpDown that changed its Increment property.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs for Increment property.</param>
        private static void OnIncrementPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            NumericUpDown nud = (NumericUpDown)d;

            EnsureValidIncrementValue(d, e);

            // Note: this section is a workaround, containing my
            // logic to hold all calls to the property changed
            // methods until after all coercion has completed
            // ----------
            if (nud._levelsFromRootCall == 0)
            {
                nud._requestedInc = (double)e.NewValue;
                nud._initialInc   = (double)e.OldValue;

                nud._levelsFromRootCall++;
                // do a check before set to avoid blowing away binding unnecessarily.
                if (nud.Increment != nud._requestedInc)
                {
                    nud.Increment = nud._requestedInc;
                }
                nud._levelsFromRootCall--;
            }
            // ----------

            // Note: this section completes my workaround to call
            // the property changed logic if all coercion has completed
            // ----------
            if (nud._levelsFromRootCall == 0)
            {
                NumericUpDownAutomationPeer peer = FrameworkElementAutomationPeer.FromElement(nud) as NumericUpDownAutomationPeer;

                double increment = nud.Increment;
                if (nud._initialInc != increment)
                {
                    if (peer != null)
                    {
                        peer.RaisePropertyChangedEvent(RangeValuePatternIdentifiers.SmallChangeProperty, nud._initialInc, increment);
                    }

                    nud.OnIncrementChanged(nud._initialInc, increment);
                }
            }
            // ----------
        }
Ejemplo n.º 7
0
        /// <summary>
        /// MaximumProperty property changed handler.
        /// </summary>
        /// <param name="d">NumericUpDown that changed its Maximum.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs for Maximum property.</param>
        private static void OnMaximumPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            EnsureValidDoubleValue(d, e);
            NumericUpDown nud = d as NumericUpDown;

            // Note: this section is a workaround, containing my
            // logic to hold all calls to the property changed
            // methods until after all coercion has completed
            // ----------
            if (nud._levelsFromRootCall == 0)
            {
                nud._requestedMax = (double)e.NewValue;
                nud._initialMax   = (double)e.OldValue;
                nud._initialVal   = nud.Value;
            }
            nud._levelsFromRootCall++;
            // ----------

            nud.CoerceMaximum();
            nud.CoerceValue();

            // Note: this section completes my workaround to call
            // the property changed logic if all coercion has completed
            // ----------
            nud._levelsFromRootCall--;
            if (nud._levelsFromRootCall == 0)
            {
                NumericUpDownAutomationPeer peer = FrameworkElementAutomationPeer.FromElement(nud) as NumericUpDownAutomationPeer;

                double maximum = nud.Maximum;
                if (nud._initialMax != maximum)
                {
                    if (peer != null)
                    {
                        peer.RaisePropertyChangedEvent(RangeValuePatternIdentifiers.MaximumProperty, nud._initialMax, maximum);
                    }

                    nud.OnMaximumChanged(nud._initialMax, maximum);
                }

                // reevaluate the valid spin direction
                nud.SetValidSpinDirection();
            }
            // ----------
        }