Exemplo n.º 1
0
        public void ReadOnlyProperties()
        {
            ScrollViewer cp = new ScrollViewer();

            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ComputedHorizontalScrollBarVisibilityProperty, Visibility.Collapsed);
            }, "ComputedHorizontalScrollBarVisibilityProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ComputedVerticalScrollBarVisibilityProperty, Visibility.Collapsed);
            }, "ComputedVerticalScrollBarVisibility");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ExtentHeightProperty, 1.0);
            }, "ExtentHeightProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ExtentWidthProperty, 1.0);
            }, "ExtentWidthProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.HorizontalOffsetProperty, 1.0);
            }, "HorizontalOffsetProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ScrollableHeightProperty, 1.0);
            }, "ScrollableHeightProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ScrollableWidthProperty, 1.0);
            }, "ScrollableWidthProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.VerticalOffsetProperty, 1.0);
            }, "VerticalOffsetProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ViewportHeightProperty, 1.0);
            }, "ViewportHeightProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ViewportWidthProperty, 1.0);
            }, "ViewportWidthProperty");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to extract the scrollbars that are within the scrollviewers
        /// visual tree. When extracted, event handlers are added to their ValueChanged events.
        /// </summary>
        private static void GetScrollBarsForScrollViewer(ScrollViewer scrollViewer)
        {
            ScrollBar scroll = GetScrollBar(scrollViewer, Orientation.Vertical);

            if (scroll != null)
            {
                // save a reference to this scrollbar on the attached property
                scrollViewer.SetValue(VerticalScrollBarProperty, scroll);

                // scroll the scrollviewer
                scrollViewer.ScrollToVerticalOffset(ScrollViewerBinding.GetVerticalOffset(scrollViewer));

                // handle the changed event to update the exposed VerticalOffset
                scroll.ValueChanged += (s, e) =>
                {
                    SetVerticalOffset(scrollViewer, e.NewValue);
                };
            }

            scroll = GetScrollBar(scrollViewer, Orientation.Horizontal);
            if (scroll != null)
            {
                // save a reference to this scrollbar on the attached property
                scrollViewer.SetValue(HorizontalScrollBarProperty, scroll);

                // scroll the scrollviewer
                scrollViewer.ScrollToHorizontalOffset(ScrollViewerBinding.GetHorizontalOffset(scrollViewer));

                // handle the changed event to update the exposed HorizontalOffset
                scroll.ValueChanged += (s, e) =>
                {
                    scrollViewer.SetValue(HorizontalOffsetProperty, e.NewValue);
                };
            }
        }
Exemplo n.º 3
0
        public void Offset_Should_Be_Coerced_To_Viewport()
        {
            var target = new ScrollViewer();
            target.SetValue(ScrollViewer.ExtentProperty, new Size(20, 20));
            target.SetValue(ScrollViewer.ViewportProperty, new Size(10, 10));
            target.Offset = new Vector(12, 12);

            Assert.Equal(new Vector(10, 10), target.Offset);
        }
Exemplo n.º 4
0
        public void Offset_Should_Be_Coerced_To_Viewport()
        {
            var target = new ScrollViewer();

            target.SetValue(ScrollViewer.ExtentProperty, new Size(20, 20));
            target.SetValue(ScrollViewer.ViewportProperty, new Size(10, 10));
            target.Offset = new Vector(12, 12);

            Assert.Equal(new Vector(10, 10), target.Offset);
        }
Exemplo n.º 5
0
        public void Test_ScrollToEnd()
        {
            var target = new ScrollViewer();

            target.SetValue(ScrollViewer.ExtentProperty, new Size(50, 50));
            target.SetValue(ScrollViewer.ViewportProperty, new Size(10, 10));
            target.Offset = new Vector(25, 25);
            target.ScrollToEnd();

            Assert.Equal(new Vector(0, 40), target.Offset);
        }
 public static void SetAutoScrollToEnd(ScrollViewer instance, bool value)
 {
     var oldHandler = (ScrollViewerAutoScrollToEndHandler)instance.GetValue(AutoScrollHandlerProperty);
     if (oldHandler != null)
     {
         oldHandler.Dispose();
         instance.SetValue(AutoScrollHandlerProperty, null);
     }
     instance.SetValue(AutoScrollProperty, value);
     if (value)
         instance.SetValue(AutoScrollHandlerProperty, new ScrollViewerAutoScrollToEndHandler(instance));
 }
Exemplo n.º 7
0
        public void Changing_Extent_Should_Raise_ScrollChanged()
        {
            var target = new ScrollViewer();
            var raised = 0;

            target.SetValue(ScrollViewer.ExtentProperty, new Size(100, 100));
            target.SetValue(ScrollViewer.ViewportProperty, new Size(50, 50));
            target.Offset = new Vector(10, 10);

            target.ScrollChanged += (s, e) =>
            {
                Assert.Equal(new Vector(11, 12), e.ExtentDelta);
                Assert.Equal(default, e.OffsetDelta);
Exemplo n.º 8
0
 public RoutesInfoHandler(List <PlanetInfo> planetInfoCSList, pgMissionCalculator parent, CheckBox chkReturn)
 {
     this.planetInfoCSList = planetInfoCSList;
     this.parent           = parent;
     this.chkReturn        = chkReturn;
     dblDVBudget           = 0;
     dblTravelTime         = 0;
     grdRouteInfo          = UIControls.grdPInit(1);
     viewer = UIControls.viewerInit();
     //viewer.MaxWidth = 500;
     viewer.Content = grdRouteInfo;
     viewer.SetValue(Grid.RowProperty, 3);
     viewer.SetValue(Grid.ColumnProperty, 1);
     parent.grdMain.Children.Add(viewer);
 }
Exemplo n.º 9
0
    void InsertTestRelation ()
    {
      if (Model.HasContentTest ()) {
        var stack = new StackPanel ();

        var scrow = new ScrollViewer
        {
          VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
          CanContentScroll= false,
        };

        scrow.SetValue (Grid.RowProperty, 3); // row 3
        scrow.Content = stack;

        m_Grid.Children.Add (scrow);

        if (Model.HasComponentControlModels) {
          foreach (var controlModel in Model.ComponentControlModels) {
            var cc = new TComponentDisplayControl
            {
              Model = controlModel
            };

            stack.Children.Add (cc);
          }
        }
      }
    }
Exemplo n.º 10
0
        public void LargeChange_Should_Be_Viewport()
        {
            var target = new ScrollViewer();

            target.SetValue(ScrollViewer.ViewportProperty, new Size(104, 143));
            Assert.Equal(new Size(104, 143), target.LargeChange);
        }
Exemplo n.º 11
0
            static void RegisterHook(ScrollViewer scrollViewer)
            {
                RemoveHook(scrollViewer);
                if (PresentationSource.FromVisual(scrollViewer) is HwndSource source)
                {
                    HwndSourceHook hook = Hook;
                    scrollViewer.SetValue(HorizontalScrollHookProperty, hook);
                    source.AddHook(hook);
                }

                IntPtr Hook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
                {
                    const int WM_MOUSEHWHEEL = 0x020E;

                    switch (msg)
                    {
                    case WM_MOUSEHWHEEL:
                        int tilt = (short)((wParam.ToInt64() >> 16) & 0xFFFF);
                        OnMouseTilt(tilt);
                        return((IntPtr)1);
                    }
                    return(IntPtr.Zero);
                }

                void OnMouseTilt(int tilt)
                {
                    scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + tilt);
                }
            }
Exemplo n.º 12
0
        public void Changing_Extent_Should_Raise_ScrollChanged()
        {
            var target = new ScrollViewer();
            var root   = new TestRoot(target);
            var raised = 0;

            target.SetValue(ScrollViewer.ExtentProperty, new Size(100, 100));
            target.SetValue(ScrollViewer.ViewportProperty, new Size(50, 50));
            target.Offset = new Vector(10, 10);

            root.LayoutManager.ExecuteInitialLayoutPass(root);

            target.ScrollChanged += (s, e) =>
            {
                Assert.Equal(new Vector(11, 12), e.ExtentDelta);
                Assert.Equal(default, e.OffsetDelta);
Exemplo n.º 13
0
 public static void SetAlwaysScrollToEnd(ScrollViewer scroll, bool alwaysScrollToEnd)
 {
     if (scroll == null)
     {
         throw new ArgumentNullException("scroll");
     }
     scroll.SetValue(AlwaysScrollToEndProperty, alwaysScrollToEnd);
 }
Exemplo n.º 14
0
 private static void SetHorizontalOffset(ScrollViewer element, double value)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     element.SetValue(ScrollViewerExtensions.HorizontalOffsetProperty, (object)value);
 }
Exemplo n.º 15
0
 public static void SetIsMouseWheelScrollingEnabled(this ScrollViewer viewer, bool value)
 {
     if (viewer == null)
     {
         throw new ArgumentNullException("viewer");
     }
     viewer.SetValue(ScrollViewerExtensions.IsMouseWheelScrollingEnabledProperty, value);
 }
Exemplo n.º 16
0
 public static void SetHandleMouseWheelFromContent(ScrollViewer scrollViewer, bool value)
 {
     if (scrollViewer is null)
     {
         throw new ArgumentNullException(nameof(scrollViewer));
     }
     scrollViewer.SetValue(HandleMouseWheelFromContentProperty, value);
 }
Exemplo n.º 17
0
 public static void SetAlwaysScrollToEnd(ScrollViewer scrollViewer, bool alwaysScrollToEnd)
 {
     if (scrollViewer is null)
     {
         throw new ArgumentNullException(nameof(scrollViewer));
     }
     scrollViewer.SetValue(AlwaysScrollToEndProperty, alwaysScrollToEnd);
 }
        public PlaneInfoHandler(pgMissionCalculator parent, List <Brush> foregroundList)
        {
            this.foregroundList    = foregroundList;
            this.parent            = parent;
            this.currentPlanetList = IO.objList;
            planetInfoCSList.Clear();
            grdPlanetInfo = UIControls.grdPInit(1);

            vrPI                = UIControls.viewerInit();
            vrPI.Name           = "vrPI";
            vrPI.MaxHeight      = 570;
            vrPI.Content        = grdPlanetInfo;
            vrPI.ScrollChanged += ScrollChanged;
            vrPI.SetValue(Grid.RowProperty, 1);
            vrPI.SetValue(Grid.ColumnProperty, 3);
            parent.pnlDown.Children.Add(vrPI);

            StackPanel pnlMainControls = UIControls.pnlInit(Orientation.Vertical);

            grdPlanetSelection = UIControls.grdPInit(1);
            vrPS                = UIControls.viewerInit();
            vrPS.Content        = grdPlanetSelection;
            vrPS.Name           = "vrPS";
            vrPS.MaxHeight      = 570;
            vrPS.ScrollChanged += ScrollChanged;
            btnAddPI            = btnAddInit();
            btnRemovePI         = btnRemovedInit();
            StackPanel pnlBtns = UIControls.pnlInit(Orientation.Horizontal);

            pnlBtns.HorizontalAlignment = HorizontalAlignment.Right;
            pnlBtns.VerticalAlignment   = VerticalAlignment.Top;
            pnlBtns.Margin     = new Thickness(0, 5, 0, 0);
            pnlBtns.Background = new SolidColorBrush {
                Color = Color.FromRgb(5, 47, 60), Opacity = 0.5
            };
            pnlBtns.Children.Add(btnAddPI);
            pnlBtns.Children.Add(btnRemovePI);
            pnlBtns.SetValue(Grid.RowProperty, 0);
            pnlBtns.SetValue(Grid.ColumnProperty, 0);
            pnlMainControls.Children.Add(vrPS);
            parent.grdTop.Children.Add(pnlBtns);
            parent.pnlDownLeft.Children.Add(pnlMainControls);

            planetInfoCSList.Add(new PlanetInfo(RowCounter + 1, grdPlanetInfo, grdPlanetSelection, foregroundList[RowCounter], this));
            routesInfo = new RoutesInfoHandler(planetInfoCSList, parent, planetInfoCSList[0].chkReturn);
        }
Exemplo n.º 19
0
 private static void SetVerticalOffset(ScrollViewer element, double value)
 {
     if (element == null)
     {
         throw new ArgumentNullException(nameof(element));
     }
     element.SetValue(VerticalOffsetProperty, value);
 }
        public void GetAlwaysScrollToEndReturnsProperBooleanValueWhenTrue()
        {
            ScrollViewer viewer = new ScrollViewer();

            viewer.SetValue(ScrollViewerExtensions.AlwaysScrollToEndProperty, true);

            Assert.IsTrue(ScrollViewerExtensions.GetAlwaysScrollToEnd(viewer));
        }
Exemplo n.º 21
0
 static void RemoveHook(ScrollViewer scrollViewer)
 {
     if (scrollViewer.GetValue(HorizontalScrollHookProperty) is HwndSourceHook hook &&
         PresentationSource.FromVisual(scrollViewer) is HwndSource source)
     {
         source.RemoveHook(hook);
         scrollViewer.SetValue(HorizontalScrollHookProperty, null);
     }
 }
Exemplo n.º 22
0
        public static void SetZoomValue(ScrollViewer scrollViewer, float value)
        {
            if (scrollViewer != null)
            {
                viewer = scrollViewer;
                viewer.ViewChanging += ViewChanging;

                scrollViewer.SetValue(ZoomValueProperty, value);
            }
        }
Exemplo n.º 23
0
        static void GetScrollbarsForScrollViewer(ScrollViewer sv)
        {
            ScrollBar scroll = sv.FindChild <ScrollBar>(s => s.Orientation == Orientation.Vertical);

            if (scroll != null)
            {
                sv.SetValue(VerticalScrollbarProperty, scroll);
                sv.ScrollToVerticalOffset(GetVerticalOffset(sv));

                scroll.ValueChanged += (s, e) => SetVerticalOffset(sv, e.NewValue);
            }
        }
Exemplo n.º 24
0
        public void ReadOnlyProperties_BadValues()
        {
            ScrollViewer cp = new ScrollViewer();

            // normally bad value types would throw ArgumentException but not for read-only properties
            // and (the important part is) that is not possible using the PropertyChangedCallback to
            // simulate a read-only property (like ScrollViewer from beta1 was doing)

            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ComputedHorizontalScrollBarVisibilityProperty, true);
            }, "ComputedHorizontalScrollBarVisibilityProperty-wrong-value-type");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ComputedVerticalScrollBarVisibilityProperty, true);
            }, "ComputedVerticalScrollBarVisibility");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ExtentHeightProperty, true);
            }, "ExtentHeightProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ExtentWidthProperty, true);
            }, "ExtentWidthProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.HorizontalOffsetProperty, true);
            }, "HorizontalOffsetProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ScrollableHeightProperty, true);
            }, "ScrollableHeightProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ScrollableWidthProperty, true);
            }, "ScrollableWidthProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.VerticalOffsetProperty, true);
            }, "VerticalOffsetProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ViewportHeightProperty, true);
            }, "ViewportHeightProperty");
            Assert.Throws <InvalidOperationException> (delegate {
                cp.SetValue(ScrollViewer.ViewportWidthProperty, true);
            }, "ViewportWidthProperty");
        }
Exemplo n.º 25
0
 public Championship(int id, Excel._Worksheet ws, List <Driver> allDrivers)
 {
     Id             = id;
     ExcelWorksheet = ws;
     ExcelRange     = ws.UsedRange;
     StarterGrid.SetValue(Control.BackgroundProperty, new SolidColorBrush(Color.FromRgb(0xCC, 0xCC, 0xCC)));
     StarterGridSV.SetValue(Grid.ColumnProperty, 0);
     RacerGrid.SetValue(Control.BackgroundProperty, new SolidColorBrush(Color.FromRgb(0xEE, 0xEE, 0xEE)));
     RacerGridSV.SetValue(Grid.ColumnProperty, 1);
     StarterGridSV.Content = StarterGrid;
     RacerGridSV.Content   = RacerGrid;
     LoadData(allDrivers);
 }
Exemplo n.º 26
0
        private static void OnKeepInCenterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ScrollViewer scroll = d as ScrollViewer;

            if ((bool)e.NewValue)
            {
                //attach the behavior
                AdvancedZooming behavior = new AdvancedZooming();
                scroll.ScrollChanged += behavior.scroll_ScrollChanged;
                scroll.SetValue(BehaviorProperty, behavior);
            }
            else
            {
                //dettach the behavior
                AdvancedZooming behavior = scroll.GetValue(BehaviorProperty) as AdvancedZooming;
                if (behavior != null)
                {
                    scroll.ScrollChanged -= behavior.scroll_ScrollChanged;
                }
                scroll.SetValue(BehaviorProperty, null);
            }
        }
Exemplo n.º 27
0
        public static void BindHorizontalOffset(ScrollViewer scrollViewer)
        {
            if (scrollViewer.GetValue(HorizontalScrollBindingProperty) != null)
            {
                return;
            }

            scrollViewer.SetValue(HorizontalScrollBindingProperty, true);
            scrollViewer.ScrollChanged += (s, se) =>
            {
                if (se.HorizontalChange == 0)
                {
                    return;
                }
                SetHorizontalOffset(scrollViewer, se.HorizontalOffset);
            };
        }
Exemplo n.º 28
0
        private static void BindVerticalOffset(ScrollViewer scrollViewer)
        {
            if (scrollViewer.GetValue(_verticalScrollBindingProperty) != null)
            {
                return;
            }

            scrollViewer.SetValue(_verticalScrollBindingProperty, true);
            scrollViewer.ScrollChanged += (s, se) =>
            {
                if (se.VerticalChange == 0)
                {
                    return;
                }
                SetVerticalOffset(scrollViewer, se.VerticalOffset);
            };
        }
Exemplo n.º 29
0
        public static void BindVerticalOffset(ScrollViewer scrollViewer)
        {
            if (scrollViewer.GetValue(VerticalScrollBindingProperty) != null)
            {
                return;
            }

            scrollViewer.SetValue(VerticalScrollBindingProperty, true);
            scrollViewer.ScrollChanged += (s, se) =>
            {
                if (se.VerticalChange == 0)
                {
                    return;
                }

                SetVerticalOffset(scrollViewer, se.VerticalOffset);
                //SetScrollableHeight(scrollViewer, (bool)(se.VerticalOffset == 0));
                SetScrollableHeight(scrollViewer, se.VerticalOffset == scrollViewer.ScrollableHeight);
            };
        }
Exemplo n.º 30
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            PART_PreviousButton = GetTemplateChild("PART_PreviousButton") as Button;
            PART_NextButton     = GetTemplateChild("PART_NextButton") as Button;
            PART_UpButton       = GetTemplateChild("PART_UpButton") as Button;
            PART_DownButton     = GetTemplateChild("PART_DownButton") as Button;
            PART_ScrollViewer   = GetTemplateChild("PART_ScrollViewer") as ScrollViewer;
            PART_Rectangle      = GetTemplateChild("PART_Rectangle") as Rectangle;
            if (PART_PreviousButton != null)
            {
                PART_PreviousButton.Click += PART_PreviousButton_Click;
            }
            if (PART_NextButton != null)
            {
                PART_NextButton.Click += PART_NextButton_Click;
            }
            if (PART_UpButton != null)
            {
                PART_UpButton.Click += PART_UpButton_Click;
            }
            if (PART_DownButton != null)
            {
                PART_DownButton.Click += PART_DownButton_Click;
            }
            if (PART_ScrollViewer != null)
            {
                PART_ScrollViewer.ScrollChanged += PART_ScrollViewer_ScrollChanged;
            }
            if (PART_Rectangle != null)
            {
                PART_Rectangle.IsVisibleChanged += PART_Rectangle_IsVisibleChanged;
            }

            PART_ScrollViewer.SetValue(ScrollViewerBehavior.VerticalOffsetProperty, 0.0);
        }
Exemplo n.º 31
0
 public static void SetUseHorizontalScrolling(ScrollViewer element, bool value)
 => element.SetValue(UseHorizontalScrollingProperty, value);