示例#1
0
        public void Thumb_DragComplete_Event_Should_Raise_Scroll_Event()
        {
            var target = new ScrollBar
            {
                Template = new FuncControlTemplate <ScrollBar>(Template),
            };

            target.ApplyTemplate();

            var track = (Track)target.GetTemplateChildren().First(x => x.Name == "track");

            var raisedEvent = Assert.Raises <ScrollEventArgs>(
                handler => target.Scroll += handler,
                handler => target.Scroll -= handler,
                () =>
            {
                var ev = new VectorEventArgs
                {
                    RoutedEvent = Thumb.DragCompletedEvent,
                    Vector      = new Vector(0, 0)
                };

                track.Thumb.RaiseEvent(ev);
            });

            Assert.Equal(ScrollEventType.EndScroll, raisedEvent.Arguments.ScrollEventType);
        }
示例#2
0
        public void Setting_Track_Value_Should_Update_Value()
        {
            var target = new ScrollBar
            {
                Template = new FuncControlTemplate <ScrollBar>(Template),
            };

            target.ApplyTemplate();
            var track = (Track)target.GetTemplateChildren().First(x => x.Name == "track");

            track.Value = 50;

            Assert.Equal(target.Value, 50);
        }
示例#3
0
        public void Setting_Value_Should_Update_Track_Value()
        {
            var target = new ScrollBar
            {
                Template = new FuncControlTemplate <ScrollBar>(Template),
            };

            target.ApplyTemplate();
            var track = target.GetTemplateChild <Track>("track");

            target.Value = 50;

            Assert.Equal(track.Value, 50);
        }
        private static void Optimize(ScrollBar bar)
        {
            // Some ScrollBars still don't have Buttons when the Loaded-Event is raised. We have to
            // apply the Template manually so we can replace the Commands.
            // That call isn't that bad because ApplyTemplate only does something if the Template
            // wasn't already applied.
            bar.ApplyTemplate();

            foreach (ButtonBase button in GetVisualDescendants(bar).OfType <ButtonBase>())
            {
                // The Buttons in a ScrollBar can always stay enabled, in cases when there is nothing
                // to scroll the whole ScrollBar disables itself anyway. Therefor we can use a
                // AlwaysExecutableRoutedCommand here.
                if (button.Command is RoutedCommand)
                {
                    button.Command = new AlwaysExecutableRoutedCommand((RoutedCommand)button.Command, button);
                }
            }
        }