Exemplo n.º 1
0
        void MainCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            const double ScaleRate = 1.1;

            Point mouseAtMainCanvas   = e.GetPosition(MainCanvas);
            Point mouseAtScrollViewer = e.GetPosition(MainScrollViewer);

            ScaleTransform st = MainCanvas.LayoutTransform as ScaleTransform;

            if (e.Delta > 0 && st.ScaleX < 64)
            {
                st.ScaleX = st.ScaleY = st.ScaleX * ScaleRate;
            }
            else if (st.ScaleX > 0.2)
            {
                st.ScaleX = st.ScaleY = st.ScaleX / ScaleRate;
            }

            MainScrollViewer.ScrollToHorizontalOffset(0);
            MainScrollViewer.ScrollToVerticalOffset(0);
            UpdateLayout();

            Vector offset = MainCanvas.TranslatePoint(mouseAtMainCanvas, MainScrollViewer) - mouseAtScrollViewer;

            MainScrollViewer.ScrollToHorizontalOffset(offset.X);
            MainScrollViewer.ScrollToVerticalOffset(offset.Y);
            UpdateLayout();

            e.Handled = true;
        }
 private void Jpht_OnHyperTextClick(object sender, EventArgs e)
 {
     try {
         CurrentEntry = (JPDictionaryEntry)sender;
         MainScrollViewer.ScrollToVerticalOffset(0);
     }
     catch (Exception) { }
 }
Exemplo n.º 3
0
 private void MainScrollViewer_MouseMove(object sender, MouseEventArgs e)
 {
     Cursor = Cursors.Arrow;
     if (e.MiddleButton == MouseButtonState.Pressed)
     {
         MainScrollViewer.ScrollToHorizontalOffset(MainScrollViewer.HorizontalOffset + MiddleMousePressPoint.X - e.GetPosition(MainScrollViewer).X);
         MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset + MiddleMousePressPoint.Y - e.GetPosition(MainScrollViewer).Y);
         MiddleMousePressPoint = e.GetPosition(MainScrollViewer);
         Cursor = Cursors.ScrollAll;
     }
 }
Exemplo n.º 4
0
        void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (lastDragPoint.HasValue)
            {
                Point posNow = e.GetPosition(MainScrollViewer);

                double dX = posNow.X - lastDragPoint.Value.X;
                double dY = posNow.Y - lastDragPoint.Value.Y;

                lastDragPoint = posNow;

                MainScrollViewer.ScrollToHorizontalOffset(MainScrollViewer.HorizontalOffset - dX);
                MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset - dY);
            }
        }
Exemplo n.º 5
0
        void OnScrollViewerScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (e.ExtentHeightChange != 0 || e.ExtentWidthChange != 0)
            {
                Point?targetBefore = null;
                Point?targetNow    = null;

                if (!lastMousePositionOnTarget.HasValue)
                {
                    if (lastCenterPositionOnTarget.HasValue)
                    {
                        var   centerOfViewport  = new Point(MainScrollViewer.ViewportWidth / 2, MainScrollViewer.ViewportHeight / 2);
                        Point centerOfTargetNow = MainScrollViewer.TranslatePoint(centerOfViewport, MainCanvas);

                        targetBefore = lastCenterPositionOnTarget;
                        targetNow    = centerOfTargetNow;
                    }
                }
                else
                {
                    targetBefore = lastMousePositionOnTarget;
                    targetNow    = Mouse.GetPosition(MainCanvas);

                    lastMousePositionOnTarget = null;
                }

                if (targetBefore.HasValue)
                {
                    double dXInTargetPixels = targetNow.Value.X - targetBefore.Value.X;
                    double dYInTargetPixels = targetNow.Value.Y - targetBefore.Value.Y;

                    double multiplicatorX = e.ExtentWidth / MainCanvas.Width;
                    double multiplicatorY = e.ExtentHeight / MainCanvas.Height;

                    double newOffsetX = MainScrollViewer.HorizontalOffset - dXInTargetPixels * multiplicatorX;
                    double newOffsetY = MainScrollViewer.VerticalOffset - dYInTargetPixels * multiplicatorY;

                    if (double.IsNaN(newOffsetX) || double.IsNaN(newOffsetY))
                    {
                        return;
                    }

                    MainScrollViewer.ScrollToHorizontalOffset(newOffsetX);
                    MainScrollViewer.ScrollToVerticalOffset(newOffsetY);
                }
            }
        }
Exemplo n.º 6
0
 private void RoutedViewHost_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
 {
     // force scrolling to be handled by the main scroll viewer
     // rather than the routed view host
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset - e.Delta);
 }
Exemplo n.º 7
0
 private void UIElement_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
 {
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset - e.Delta / 3);
 }
Exemplo n.º 8
0
 private void MainScrollViewer_DoMouseWheel(MouseWheelEventArgs e)
 {
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset - e.Delta);
 }
        /// <summary>
        /// Use this method to get older messages when VerticalOffset reaches 0 (scrolled to top)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void MainScrollViewer_OnScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (!_stopLoading && !_reachedEnd && Math.Abs(e.VerticalOffset) < 1) // load more messages
            {
                _stopLoading = true;
                // get last height
                double lastHeight = MainScrollViewer.ScrollableHeight;
                var    messages   = await SharedStuff.Database.QueryAsync <DatabaseHelper.Messages>
                                        (DatabaseHelper.LastRowsQuery(_lastMessageIndex, 100), Username);

                _lastMessageIndex += 100;
                // check if we have reached the end
                if (messages.Count < 100)
                {
                    _reachedEnd = true;
                }
                if (messages.Count == 0)
                {
                    return;
                }
                // insert these messages at the end of the list view (that is first of the collation)
                foreach (var message in messages)
                {
                    /*MessagesList.Insert(0, new ChatMessagesNotify
                     * {
                     *  MyMessage = message.MyMessage,
                     *  Message = message.Payload,
                     *  FullDate = message.Date,
                     *  Type = message.Type
                     * });*/
                    if (message.Type == 0)
                    {
                        MessagesList.Insert(0, new ChatMessagesNotify
                        {
                            MyMessage = message.MyMessage,
                            Message   = message.Payload,
                            FullDate  = message.Date,
                            Type      = message.Type,
                            Sent      = 0,
                            Progress  = 101
                        });
                    }
                    else if (message.Type == 1)
                    {
                        var fileInfo = await SharedStuff.Database.Table <DatabaseHelper.Files>()
                                       .FirstAsync(file => file.Token == message.Payload);

                        var downloadButtonIcon = PackIconKind.Download;
                        if (!string.IsNullOrEmpty(fileInfo.Location))
                        {
                            downloadButtonIcon = File.Exists(fileInfo.Location) ? PackIconKind.File : PackIconKind.DownloadOff;
                        }
                        MessagesList.Insert(0, new ChatMessagesNotify
                        {
                            MyMessage          = message.MyMessage,
                            Message            = fileInfo.Name,
                            FullDate           = message.Date,
                            Type               = message.Type,
                            Sent               = 0,
                            Token              = message.Payload,
                            DownloadButtonIcon = downloadButtonIcon,
                            Progress           = 101
                        });
                    }
                }
                MainScrollViewer.UpdateLayout();
                MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.ScrollableHeight - lastHeight); // tricky part; calculate the delta of height adding and go to that position from top
                MainScrollViewer.UpdateLayout();
                _stopLoading = false;
            }
        }
 private void PaymentCollectionOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset + 120);
 }
 private void PaymentListView_OnMouseWheel(object sender, MouseWheelEventArgs e)
 {
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset + (e.Delta * -1));
 }
Exemplo n.º 12
0
 private void SFXListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
 {
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset - e.Delta);
     e.Handled = true;
 }
 private void WordListBox_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
 {
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset - e.Delta);
     e.Handled = true;
 }
Exemplo n.º 14
0
        private async void OnFrameworkElementTapped(object sender, TappedRoutedEventArgs e)
        {
            if (sender is ContentPresenter contentPresenter)
            {
                var tag = contentPresenter.Tag.ToString();
                switch (_tabLayoutType)
                {
                case TabLayoutType.Item1ContentState:
                    Item1VerticalOffset = MainScrollViewer.VerticalOffset;
                    break;

                case TabLayoutType.Item2ContentState:
                    Item2VerticalOffset = MainScrollViewer.VerticalOffset;
                    break;

                case TabLayoutType.Item3ContentState:
                    Item3VerticalOffset = MainScrollViewer.VerticalOffset;
                    break;

                case TabLayoutType.Item4ContentState:
                    Item4VerticalOffset = MainScrollViewer.VerticalOffset;
                    break;

                case TabLayoutType.Item5ContentState:
                    Item5VerticalOffset = MainScrollViewer.VerticalOffset;
                    break;

                case TabLayoutType.Item6ContentState:
                    Item6VerticalOffset = MainScrollViewer.VerticalOffset;
                    break;

                default:
                    break;
                }
                await Task.Delay(100).ConfigureAwait(false);

                _tabLayoutType = (TabLayoutType)Enum.Parse(typeof(TabLayoutType), tag);
                SetState(_tabLayoutType);
                await Task.Delay(100).ConfigureAwait(false);

                switch (_tabLayoutType)
                {
                case TabLayoutType.Item1ContentState:
                    if (Item1VerticalOffset > 0)
                    {
                        ScrollToVerticalOffset(Item1VerticalOffset);
                    }
                    if (!Item1Init)
                    {
                        RefreshAction1?.Invoke();
                        Item1Init = true;
                    }
                    break;

                case TabLayoutType.Item2ContentState:
                    if (Item2VerticalOffset > 0)
                    {
                        ScrollToVerticalOffset(Item2VerticalOffset);
                    }
                    if (!Item2Init)
                    {
                        RefreshAction2?.Invoke();
                        Item2Init = true;
                    }
                    break;

                case TabLayoutType.Item3ContentState:
                    if (Item3VerticalOffset > 0)
                    {
                        ScrollToVerticalOffset(Item3VerticalOffset);
                    }
                    if (!Item3Init)
                    {
                        RefreshAction3?.Invoke();
                        Item3Init = true;
                    }
                    break;

                case TabLayoutType.Item4ContentState:
                    if (Item4VerticalOffset > 0)
                    {
                        ScrollToVerticalOffset(Item4VerticalOffset);
                    }
                    if (!Item4Init)
                    {
                        RefreshAction4?.Invoke();
                        Item4Init = true;
                    }
                    break;

                case TabLayoutType.Item5ContentState:
                    if (Item5VerticalOffset > 0)
                    {
                        ScrollToVerticalOffset(Item5VerticalOffset);
                    }
                    if (!Item5Init)
                    {
                        RefreshAction5?.Invoke();
                        Item5Init = true;
                    }
                    break;

                case TabLayoutType.Item6ContentState:
                    if (Item6VerticalOffset > 0)
                    {
                        ScrollToVerticalOffset(Item6VerticalOffset);
                    }
                    if (!Item6Init)
                    {
                        RefreshAction6?.Invoke();
                        Item6Init = true;
                    }
                    break;

                default:
                    break;
                }
            }
            async void ScrollToVerticalOffset(double offset)
            {
                await Helper.RunOnUI(() =>
                {
                    MainScrollViewer.ScrollToVerticalOffset(offset);
                });
            }
        }
Exemplo n.º 15
0
 private void ScreenshotsListbox_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
 {
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset - e.Delta);
 }
Exemplo n.º 16
0
 private void UIElement_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
 {
     // Redirect vertical scrolling to parent scroll viewer
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset + (e.Delta * -0.5));
 }