Exemplo n.º 1
0
        protected override Size MeasureOverride(Size availableSize)
        {
            LatestAvailableSize = availableSize;

            if ((availableSize.Width == 0) || (availableSize.Height == 0))
            {
                return(new Size(0, 0));
            }

            double width  = Double.IsInfinity(availableSize.Width) ? availableSize.Width : availableSize.Width - Padding.Left - Padding.Right;
            double height = Double.IsInfinity(availableSize.Height) ? availableSize.Height : availableSize.Height - Padding.Top - Padding.Bottom;

            if ((width > 0) && (height > 0))
            {
                wrapper.Measure(new Size(width, height));

                MeasureBackground();

                return(new Size(wrapper.DesiredSize.Width + Padding.Left + Padding.Right, wrapper.DesiredSize.Height + Padding.Top + Padding.Bottom));
            }
            else
            {
                return(new Size(0, 0));
            }
        }
Exemplo n.º 2
0
        private async Task <bool> CheckConnection()
        {
            BusyIndicator.Visibility = Visibility.Visible;

            try
            {
                var settings = App.MainVm.Settings;
                var host     = txtHost.Text;
                if (string.IsNullOrWhiteSpace(host))
                {
                    host = "nohost";
                }



                int port;
                if (!int.TryParse(txtPort.Text, out port))
                {
                    port = 80;
                }
                if (port < 1)
                {
                    port = 80;
                }
                txtPort.Text = port.ToString();

                var xbmc = new Client(new ConnectionSettings(host, port, txtUser.Text,
                                                             txtPass.Password), new PlatformServices.PlatformServices());
                var props = await xbmc.Application.GetProperties(new GetProperties_properties()
                {
                    KODIRPC.Application.Property.Name.version
                });

                App.MainVm.Settings.Set(host, port, txtUser.Text, txtPass.Password);

                StatusHeader.Visibility   = Visibility.Visible;
                ConnectedLabel.Visibility = Visibility.Visible;
                ErrorDetails.Visibility   = Visibility.Collapsed;
                ErrorLabel.Visibility     = Visibility.Collapsed;
                ErrorDetails.Text         = "";

                return(true);
            }
            catch (Exception ex)
            {
                StatusHeader.Visibility   = Visibility.Visible;
                ConnectedLabel.Visibility = Visibility.Collapsed;
                ErrorDetails.Visibility   = Visibility.Visible;
                ErrorLabel.Visibility     = Visibility.Visible;
                ErrorDetails.Text         = ex.Message;
                return(false);
            }
            finally
            {
                BusyIndicator.Visibility = Visibility.Collapsed;
                ScrollViewer.Measure(ScrollViewer.RenderSize);
                ScrollViewer.ScrollToVerticalOffset(double.MaxValue);
            }
        }
Exemplo n.º 3
0
        public void ScrollViewerComputedVisibilityTest()
        {
            string text = @"
<ScrollViewer xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
              Width='200' Height='100' HorizontalScrollBarVisibility='Auto' VerticalScrollBarVisibility='Auto'>
    <ScrollViewer.Template>
        <ControlTemplate TargetType='{x:Type ScrollViewer}'>
            <ScrollContentPresenter x:Name='PART_ScrollContentPresenter' Content='{TemplateBinding Content}'/>
        </ControlTemplate>
    </ScrollViewer.Template>

    <Border x:Name='border'/>
</ScrollViewer>";

            ScrollViewer scrollViewer = XamlLoader.Load(XamlParser.Parse(text)) as ScrollViewer;

            scrollViewer.IsRootElement = true;
            scrollViewer.Measure(Size.Infinity);
            scrollViewer.Arrange(new Rect(scrollViewer.DesiredSize));

            Border border = NameScope.GetNameScope(scrollViewer).FindName("border") as Border;

            border.Width  = 10;
            border.Height = 10;

            Assert.AreEqual(Visibility.Collapsed, scrollViewer.ComputedHorizontalScrollBarVisibility);
            Assert.AreEqual(Visibility.Collapsed, scrollViewer.ComputedVerticalScrollBarVisibility);
            Assert.AreEqual(border.Width, scrollViewer.ExtentWidth);
            Assert.AreEqual(border.Height, scrollViewer.ExtentHeight);

            border.Width  = 1000;
            border.Height = 1000;

            Assert.AreEqual(Visibility.Visible, scrollViewer.ComputedHorizontalScrollBarVisibility);
            Assert.AreEqual(Visibility.Visible, scrollViewer.ComputedVerticalScrollBarVisibility);
            Assert.AreEqual(border.Width, scrollViewer.ExtentWidth);
            Assert.AreEqual(border.Height, scrollViewer.ExtentHeight);

            border.Width  = 10;
            border.Height = 1000;

            Assert.AreEqual(Visibility.Collapsed, scrollViewer.ComputedHorizontalScrollBarVisibility);
            Assert.AreEqual(Visibility.Visible, scrollViewer.ComputedVerticalScrollBarVisibility);
            Assert.AreEqual(border.Width, scrollViewer.ExtentWidth);
            Assert.AreEqual(border.Height, scrollViewer.ExtentHeight);

            border.Width  = 1000;
            border.Height = 10;

            Assert.AreEqual(Visibility.Visible, scrollViewer.ComputedHorizontalScrollBarVisibility);
            Assert.AreEqual(Visibility.Collapsed, scrollViewer.ComputedVerticalScrollBarVisibility);
            Assert.AreEqual(border.Width, scrollViewer.ExtentWidth);
            Assert.AreEqual(border.Height, scrollViewer.ExtentHeight);
        }
Exemplo n.º 4
0
        protected override Size MeasureOverride(Size availableSize)
        {
            if (!availableSize.IsEmpty && !Double.IsInfinity(availableSize.Width) && !Double.IsInfinity(availableSize.Height))
            {
                wrapper.Measure(availableSize);

                return(availableSize);
            }
            else
            {
                return(new Size(0, 0));
            }
        }
Exemplo n.º 5
0
        private async Task <bool> CheckConnection()
        {
            BusyIndicator.Visibility = Visibility.Visible;

            try
            {
                checkcount++;
                var settings = App.MainVm.Settings;

                int port;
                if (!int.TryParse(VlcPort.Text, out port))
                {
                    port = 8080;
                }

                VlcPort.Text = port.ToString();

                App.MainVm.Settings.SetVlc(VlcPassword.Password, port);

                await App.MainVm.Settings.CheckVlcSettings();

                StatusHeader.Visibility   = Visibility.Visible;
                ConnectedLabel.Visibility = Visibility.Visible;
                ErrorDetails.Visibility   = Visibility.Collapsed;
                ErrorLabel.Visibility     = Visibility.Collapsed;
                ErrorHint.Visibility      = Visibility.Collapsed;
                ErrorDetails.Text         = "";

                return(true);
            }
            catch (Exception ex)
            {
                StatusHeader.Visibility   = Visibility.Visible;
                ConnectedLabel.Visibility = Visibility.Collapsed;
                ErrorDetails.Visibility   = Visibility.Visible;
                ErrorLabel.Visibility     = Visibility.Visible;
                ErrorHint.Visibility      = Visibility.Visible;
                ErrorDetails.Text         = ex.Message;
                return(false);
            }
            finally
            {
                BusyIndicator.Visibility = Visibility.Collapsed;
                ScrollViewer.Measure(ScrollViewer.RenderSize);
                ScrollViewer.ScrollToVerticalOffset(double.MaxValue);
            }
        }
Exemplo n.º 6
0
 protected override void OnMouseEnter(MouseEventArgs e)
 {
     if (!SystemParameters.IsMenuDropRightAligned)
     {
         _popupElement.HorizontalOffset = 0;
     }
     else
     {
         _scrollViewerElement.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
         var scrollWidth = _scrollViewerElement.DesiredSize.Width;
         _popupElement.HorizontalOffset = scrollWidth;
     }
     if (!_popupElement.IsOpen)
     {
         _popupElement.IsOpen = true;
     }
     base.OnMouseEnter(e);
 }
Exemplo n.º 7
0
        public void ScrollViewerSize()
        {
            StackPanel             stackPanel;
            ScrollContentPresenter scrollContentPresenter;
            ScrollViewer           scrollViewer;

            stackPanel        = new StackPanel();
            stackPanel.Height = 600;

            scrollContentPresenter         = new ScrollContentPresenter();
            scrollContentPresenter.Content = stackPanel;

            scrollViewer         = new ScrollViewer();
            scrollViewer.Content = scrollContentPresenter;

            scrollViewer.Measure(new Vector2(100, 300));
            scrollViewer.Arrange(new BoundingRectangle(0, 0, 100, 300));

            Assert.AreEqual(100, scrollViewer.ActualWidth);
            Assert.AreEqual(300, scrollViewer.ActualHeight);

            Assert.AreEqual(0, scrollContentPresenter.Extent.X);
            Assert.AreEqual(600, scrollContentPresenter.Extent.Y);

            Assert.AreEqual(100, scrollContentPresenter.Viewport.X);
            Assert.AreEqual(300, scrollContentPresenter.Viewport.Y);

            Assert.AreEqual(0, scrollContentPresenter.Offset.X);
            Assert.AreEqual(0, scrollContentPresenter.Offset.Y);

            scrollContentPresenter.SetVerticalOffset(100);

            Assert.AreEqual(0, scrollContentPresenter.Offset.X);
            Assert.AreEqual(100, scrollContentPresenter.Offset.Y);

            Assert.AreEqual(100, scrollContentPresenter.Viewport.X);
            Assert.AreEqual(300, scrollContentPresenter.Viewport.Y);
        }
Exemplo n.º 8
0
        public void TestScrolling()
        {
            const float elementWidth  = 100;
            const float elementHeight = 200;
            const float elementDepth  = 300;

            var rand         = new Random();
            var scrollViewer = new ScrollViewer {
                ScrollMode = ScrollingMode.HorizontalVertical, Width = elementWidth, Height = elementHeight, Depth = elementDepth
            };

            scrollViewer.Measure(Vector3.Zero);
            scrollViewer.Arrange(Vector3.Zero, false);

            // tests that no crashes happen with no content
            scrollViewer.ScrollTo(rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollOf(rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.Horizontal);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.InDepth);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);

            // tests with an arranged element
            const float contentWidth  = 1000;
            const float contentHeight = 2000;
            const float contentDepth  = 3000;
            var         content       = new ContentDecorator {
                Width = contentWidth, Height = contentHeight, Depth = contentDepth
            };

            scrollViewer.Content = content;
            scrollViewer.Measure(Vector3.Zero);
            scrollViewer.Arrange(Vector3.Zero, false);

            var scrollValue = new Vector3(123, 456, 789);

            scrollViewer.ScrollTo(scrollValue);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);

            scrollViewer.ScrollToEnd(Orientation.Horizontal);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, scrollValue.Y, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.Vertical);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.InDepth);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);

            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            Assert.AreEqual(new Vector3(0, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.Vertical);
            Assert.AreEqual(new Vector3(0, 0, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            Assert.AreEqual(new Vector3(0, 0, 0), scrollViewer.ScrollPosition);

            scrollViewer.ScrollOf(scrollValue);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);

            // tests with an not arranged element
            content.InvalidateArrange();
            scrollViewer.ScrollTo(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);
            content.InvalidateArrange();
            scrollViewer.ScrollOf(2 * scrollValue);
            scrollViewer.ScrollTo(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);

            content.InvalidateArrange();
            scrollViewer.ScrollToEnd(Orientation.Horizontal);
            scrollViewer.ScrollToEnd(Orientation.Vertical);
            scrollViewer.ScrollToEnd(Orientation.InDepth);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);

            content.InvalidateArrange();
            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            scrollViewer.ScrollToBeginning(Orientation.Vertical);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(0, 0, 0), scrollViewer.ScrollPosition);

            content.InvalidateArrange();
            scrollViewer.ScrollOf(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);
            content.InvalidateArrange();
            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            scrollViewer.ScrollToBeginning(Orientation.Vertical);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            scrollViewer.ScrollOf(scrollValue);
            scrollViewer.ScrollOf(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(2 * scrollValue.X, 2 * scrollValue.Y, 0), scrollViewer.ScrollPosition);
        }
Exemplo n.º 9
0
        public void TestScrolling()
        {
            const float elementWidth = 100;
            const float elementHeight = 200;
            const float elementDepth = 300;

            var rand = new Random();
            var scrollViewer = new ScrollViewer { ScrollMode = ScrollingMode.HorizontalVertical, Width = elementWidth, Height = elementHeight, Depth = elementDepth };
            scrollViewer.Measure(Vector3.Zero);
            scrollViewer.Arrange(Vector3.Zero, false);

            // tests that no crashes happen with no content
            scrollViewer.ScrollTo(rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollOf(rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.Horizontal);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.InDepth);
            Assert.AreEqual(Vector3.Zero, ScrollPosition);

            // tests with an arranged element
            const float contentWidth = 1000;
            const float contentHeight = 2000;
            const float contentDepth = 3000;
            var content = new ContentDecorator { Width = contentWidth, Height = contentHeight, Depth = contentDepth };
            scrollViewer.Content = content;
            scrollViewer.Measure(Vector3.Zero);
            scrollViewer.Arrange(Vector3.Zero, false);

            var scrollValue = new Vector3(123, 456, 789);
            scrollViewer.ScrollTo(scrollValue);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);

            scrollViewer.ScrollToEnd(Orientation.Horizontal);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, scrollValue.Y, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.Vertical);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToEnd(Orientation.InDepth);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);

            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            Assert.AreEqual(new Vector3(0, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.Vertical);
            Assert.AreEqual(new Vector3(0, 0, 0), scrollViewer.ScrollPosition);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            Assert.AreEqual(new Vector3(0, 0, 0), scrollViewer.ScrollPosition);

            scrollViewer.ScrollOf(scrollValue);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);

            // tests with an not arranged element
            content.InvalidateArrange();
            scrollViewer.ScrollTo(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);
            content.InvalidateArrange();
            scrollViewer.ScrollOf(2*scrollValue);
            scrollViewer.ScrollTo(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);

            content.InvalidateArrange();
            scrollViewer.ScrollToEnd(Orientation.Horizontal);
            scrollViewer.ScrollToEnd(Orientation.Vertical);
            scrollViewer.ScrollToEnd(Orientation.InDepth);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(contentWidth - elementWidth, contentHeight - elementHeight, 0), scrollViewer.ScrollPosition);

            content.InvalidateArrange();
            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            scrollViewer.ScrollToBeginning(Orientation.Vertical);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(0, 0, 0), scrollViewer.ScrollPosition);

            content.InvalidateArrange();
            scrollViewer.ScrollOf(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(scrollValue.X, scrollValue.Y, 0), scrollViewer.ScrollPosition);
            content.InvalidateArrange();
            scrollViewer.ScrollToBeginning(Orientation.Horizontal);
            scrollViewer.ScrollToBeginning(Orientation.Vertical);
            scrollViewer.ScrollToBeginning(Orientation.InDepth);
            scrollViewer.ScrollOf(scrollValue);
            scrollViewer.ScrollOf(scrollValue);
            scrollViewer.Arrange(Vector3.Zero, false);
            Assert.AreEqual(new Vector3(2*scrollValue.X, 2*scrollValue.Y, 0), scrollViewer.ScrollPosition);
        }
Exemplo n.º 10
0
 protected override Size MeasureOverride(Size availableSize)
 {
     scrollViewer.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
     TerminalSize = scrollViewer.DesiredSize;
     return(scrollViewer.DesiredSize);
 }
Exemplo n.º 11
0
        /// <summary>
        /// Reports when a combo box's popup opens.
        /// </summary>
        /// <param name="e">The event data for the <see cref="E:System.Windows.Controls.ComboBox.DropDownOpened"/> event.</param>
        protected override void OnDropDownOpened(EventArgs e)
        {
            base.OnDropDownOpened(e);
            Mouse.Capture(this, CaptureMode.SubTree);
            if (SelectedItem != null)
            {
                Keyboard.Focus(ItemContainerGenerator.ContainerFromItem(SelectedItem) as IInputElement);
            }
            focusedElement = Keyboard.FocusedElement;
            focusedElement.LostKeyboardFocus += OnFocusedElementLostKeyboardFocus;

            canSizeX = true;
            canSizeY = true;

            galleryPanel.Width  = double.NaN;
            scrollViewer.Height = double.NaN;

            FrameworkElement popupChild = popup.Child as FrameworkElement;

            scrollViewer.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            popupChild.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            popup.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            double heightDelta = popupChild.DesiredSize.Height - scrollViewer.DesiredSize.Height;

            double initialHeight = Math.Min(RibbonControl.GetControlWorkArea(this).Height * 2 / 3, MaxDropDownHeight);

            if (!double.IsNaN(DropDownHeight))
            {
                initialHeight = Math.Min(DropDownHeight, MaxDropDownHeight);
            }
            if (scrollViewer.DesiredSize.Height > initialHeight)
            {
                scrollViewer.Height = initialHeight;
            }
            else
            {
                initialHeight = scrollViewer.DesiredSize.Height;
            }

            Rect   monitor = RibbonControl.GetControlMonitor(this);
            double delta   = monitor.Bottom - this.PointToScreen(new Point()).Y - ActualHeight - initialHeight - heightDelta;

            if (delta >= 0)
            {
                ShowPopupOnTop = false;
            }
            else
            {
                double deltaTop = this.PointToScreen(new Point()).Y - initialHeight - heightDelta - monitor.Top;
                if (deltaTop > delta)
                {
                    ShowPopupOnTop = true;
                }
                else
                {
                    ShowPopupOnTop = false;
                }

                if (deltaTop < 0)
                {
                    delta = Math.Max(Math.Abs(delta), Math.Abs(deltaTop));
                    if (delta > galleryPanel.GetItemSize().Height)
                    {
                        scrollViewer.Height = delta;
                    }
                    else
                    {
                        canSizeY            = false;
                        scrollViewer.Height = galleryPanel.GetItemSize().Height;
                    }
                }
            }
            popupChild.UpdateLayout();
        }