public void PrimitiveUnion_CorrectlyConvertsUInt64Values()
        {
            var union1 = new PrimitiveUnion((UInt64)123412341234);

            TheResultingValue(union1.AsUInt64())
            .ShouldBe(123412341234);
        }
        public void PrimitiveUnion_CorrectlyConvertsCharValues()
        {
            var union1 = new PrimitiveUnion('@');

            TheResultingValue(union1.AsChar())
            .ShouldBe('@');
        }
        public void PrimitiveUnion_CorrectlyConvertsDoubleValues()
        {
            var union1 = new PrimitiveUnion(1234567890.123456789);

            TheResultingValue(union1.AsDouble())
            .ShouldBe(1234567890.123456789);
        }
        public void PrimitiveUnion_CorrectlyConvertsByteValues()
        {
            var union1 = new PrimitiveUnion((Byte)123);

            TheResultingValue(union1.AsByte())
            .ShouldBe(123);
        }
        public void PrimitiveUnion_CorrectlyConvertsInt64Values()
        {
            var union1 = new PrimitiveUnion(123412341234);
            var union2 = new PrimitiveUnion(-234523452345);

            TheResultingValue(union1.AsInt64())
            .ShouldBe(123412341234);
            TheResultingValue(union2.AsInt64())
            .ShouldBe(-234523452345);
        }
        /// <summary>
        /// Occurs when the scroll bar receives a <see cref="Thumb.DragDelta"/> event.
        /// </summary>
        /// <param name="hchange">The distance that the thumb moved horizontally.</param>
        /// <param name="vchange">The distance that the thumb moved vertically.</param>
        protected virtual void OnThumbDragDelta(Double hchange, Double vchange)
        {
            if (hchange == 0 && vchange == 0)
            {
                return;
            }

            var valueDelta = Track.ValueFromDistance(hchange, vchange);

            if (!Double.IsNaN(valueDelta) && valueDelta != 0.0)
            {
                var valueAfterChange = Math.Max(Minimum, Math.Min(Value + valueDelta, Maximum));

                const Double MaximumPerpendicularDistance = 150.0;

                var perpendicularDistance = Math.Abs((Track.Orientation == Orientation.Horizontal) ? vchange : hchange);
                if (perpendicularDistance > MaximumPerpendicularDistance)
                {
                    valueAfterChange = valueAtStartOfDrag;
                }

                if (IsPartOfScrollViewer)
                {
                    var command       = (Track.Orientation == Orientation.Horizontal) ? ScrollBar.DeferScrollToHorizontalOffsetCommand : ScrollBar.DeferScrollToVerticalOffsetCommand;
                    var commandParam  = new PrimitiveUnion(valueAfterChange);
                    var commandTarget = (TemplatedParent as IInputElement) ?? this;
                    if (command.CanExecute(View, null, commandParam, commandTarget))
                    {
                        command.Execute(View, null, commandParam, commandTarget);
                    }
                    else
                    {
                        command = (Track.Orientation == Orientation.Horizontal) ? ScrollBar.ScrollToHorizontalOffsetCommand : ScrollBar.ScrollToVerticalOffsetCommand;
                        if (command.CanExecute(View, null, commandParam, commandTarget))
                        {
                            command.Execute(View, null, commandParam, commandTarget);
                        }
                    }
                }
                else
                {
                    Value = valueAfterChange;
                }
                RaiseScrollEvent(ScrollEventType.ThumbTrack);
            }
        }