Пример #1
0
        private void NewPacient_OnClick(object sender, RoutedEventArgs e)
        {
            var viewModel = DataContext as MammaViewModel;

            if (viewModel != null && viewModel.SaveCommand.CanExecute(null))
            {
                var dialogResult = MessageBox.Show("Есть несохраненные изменения. Сохранить их?", "УЗД молочной железы",
                                                   MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes);
                switch (dialogResult)
                {
                case MessageBoxResult.Yes:
                    viewModel.SaveCommand.Execute(null);
                    break;

                case MessageBoxResult.Cancel:
                    return;
                }
            }
            else
            {
                var dialogResult = MessageBox.Show("Вы уверны, что хотите начать прием нового пациента?",
                                                   "УЗД молочной железы",
                                                   MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
                if (dialogResult == MessageBoxResult.No)
                {
                    return;
                }
            }

            DataContext = ContainerFactory.Get <MammaViewModel>();

            MainScrollViewer.ScrollToTop();
        }
 public MainWindow()
 {
     InitializeComponent();
     MainVm = (MainVM)this.DataContext;
     MainVm.SetPassFunc(() => PasswordBox.Password, () => PasswordBox.Password = string.Empty);
     MainVm.ContentChanged += () => MainScrollViewer.ScrollToTop();
 }
Пример #3
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;
        }
Пример #4
0
 //перевод scrollbar в нижнее положение
 public void ScrollToEnd()
 {
     if (MainScrollViewer.VerticalOffset == MainScrollViewer.ScrollableHeight)
     {
         MainScrollViewer.ScrollToEnd();
     }
 }
 private void Jpht_OnHyperTextClick(object sender, EventArgs e)
 {
     try {
         CurrentEntry = (JPDictionaryEntry)sender;
         MainScrollViewer.ScrollToVerticalOffset(0);
     }
     catch (Exception) { }
 }
Пример #6
0
        private double GetRelativeOffset()
        {
            ScrollContentPresenter scp       = MainScrollViewer.GetFirstDescendantOfType <ScrollContentPresenter>();
            FrameworkElement       content   = scp?.Content as FrameworkElement;
            GeneralTransform       transform = ScrollingTabs.TransformToVisual(content);

            return(transform.TransformPoint(new Point(0, 0)).Y - MainScrollViewer.VerticalOffset);
        }
Пример #7
0
 void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (isMoveMode)
     {
         MainScrollViewer.Cursor = Cursors.Arrow;
         MainScrollViewer.ReleaseMouseCapture();
         lastDragPoint = null;
     }
 }
Пример #8
0
        // Adds the course buttons.
        public void addButtons(SortedList <String, CourseItem> courseList)
        {
            // Electrical has 30 4th year courses!!!

            Grid fadeIn  = fadePanels[currrentPanel++ % 2];
            Grid fadeOut = fadePanels[currrentPanel % 2];

            StackPanel[] cols = { fadeIn.Children[0] as StackPanel, fadeIn.Children[1] as StackPanel, fadeIn.Children[2] as StackPanel, fadeIn.Children[3] as StackPanel };

            // Clear old courses.
            foreach (StackPanel c in cols)
            {
                c.Children.Clear();
            }

            //cols = new StackPanel[]{ fadeIn.Children[0] as StackPanel, fadeIn.Children[1] as StackPanel, fadeIn.Children[2] as StackPanel, fadeIn.Children[3] as StackPanel };

            // Actually add courses.
            int currentCol = 0;

            foreach (KeyValuePair <String, CourseItem> kvp in courseList)
            {
                CourseButton button = new CourseButton()
                {
                    CourseTitle = kvp.Value.Name,
                    CourseCode  = kvp.Key,
                    CourseItem  = kvp.Value
                };
                button.PreviewTouchDown += ClickCourse;
                button.PreviewMouseDown += ClickCourse;

                cols[currentCol].Children.Add(button);
                currentCol = (currentCol + 1) % cols.Length;

                // Add courses to lines alternatively (eg:  line 1, 2, 1, 2 etc).
                //panelLines[line++ % panelLines.Count()].Children.Add(button);

                // Make button the colour of that specialisation.
                setButtonColour(button);
            }

            fadeIn.Opacity = 0;

            Storyboard sb1 = (Storyboard)Resources["FadeOut"];
            Storyboard sb2 = (Storyboard)Resources["FadeIn"];

            sb1.Completed += FadeOut_Completed;

            sb1.SeekAlignedToLastTick(new TimeSpan(0, 0, 10));
            sb2.SeekAlignedToLastTick(new TimeSpan(0, 0, 10));

            MainScrollViewer.ScrollToTop();

            sb1.Begin(fadeOut);
            sb2.Begin(fadeIn);
        }
        private async void Page_OnLoaded(object sender, RoutedEventArgs e)
        {
            // load name of the user
            Title = "Chatting with " + (await SharedStuff.Database.Table <DatabaseHelper.Users>().Where(row => row.Username == Username)
                                        .FirstAsync()).Name;
            // load fist 100 messages
            var messages = await SharedStuff.Database.QueryAsync <DatabaseHelper.Messages>
                               (DatabaseHelper.LastRowsQuery(0, 100), Username);

            if (messages.Count < 100) // prevent additional load on db
            {
                _reachedEnd = true;
            }
            foreach (var message in messages)
            {
                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.ScrollToBottom(); // Go to the last of scroll view that is actually the first of it
            MainScrollViewer.UpdateLayout();
            _stopLoading = false;
        }
Пример #10
0
        private void ProductionCalendarDataGrid_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            e.Handled = true;

            var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
            {
                RoutedEvent = MouseWheelEvent
            };

            MainScrollViewer.RaiseEvent(eventArg);
        }
Пример #11
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;
     }
 }
Пример #12
0
        private void BackersGridView_OnLoaded(object sender, RoutedEventArgs e)
        {
            var scrollbars = MainScrollViewer.GetDescendantsOfType <ScrollBar>().ToList();

            var bar = scrollbars.FirstOrDefault(x => x.Orientation == Orientation.Horizontal);

            if (bar != null)
            {
                bar.Scroll += BarScroll;
            }

            MainScrollViewer.ViewChanged += MainScrollViewerOnViewChanged;
        }
Пример #13
0
        private void OpenProjects()
        {
            //TODO: Move to controller

            var controller = new WorkProjectsController(_ctx);

            var uc = new WorkProjectsView(controller);

            controller.BlazeAdded            += () => MainScrollViewer.ScrollToRightEnd();
            controller.RemoveDialogRequested += ShowRemoveDialog;

            FrameOpt.Content = uc;
        }
    private void LogViewer_Loaded(object sender, RoutedEventArgs e)
    {
        MainScrollViewer.ScrollToBottom();

        // TODO: Unsubscribe when closing log viewer
        // Scroll to bottom when a new log is added
        ViewModel.LogItems.CollectionChanged += async(_, ee) =>
        {
            if (ee.Action == NotifyCollectionChangedAction.Add)
            {
                await Dispatcher.InvokeAsync(() => MainScrollViewer.ScrollToBottom());
            }
        };
    }
Пример #15
0
        private void ToolBox_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Label lb = sender as Label;

            switch (lb.Content)
            {
            case "Move":
                this.isMoveMode = !isMoveMode;
                break;

            case "Zoom in":
                if (Zoom <= 2)
                {
                    Zoom += .05;
                    scaleTransform.ScaleX = Zoom;
                    scaleTransform.ScaleY = Zoom;

                    var centerOfViewport = new Point(MainScrollViewer.ViewportWidth / 2, MainScrollViewer.ViewportHeight / 2);
                    lastCenterPositionOnTarget = MainScrollViewer.TranslatePoint(centerOfViewport, GridWorkspace);
                    if (!lbZoomOut.IsEnabled)
                    {
                        lbZoomOut.IsEnabled  = true;
                        lbZoomOut.Foreground = Brushes.White;
                    }
                }
                else
                {
                    lb.IsEnabled = false;
                }
                break;

            case "Zoom out":
                if (Zoom > 0.3)
                {
                    Zoom -= .05;
                    scaleTransform.ScaleX = Zoom;
                    scaleTransform.ScaleY = Zoom;

                    var centerOfViewport1 = new Point(MainScrollViewer.ViewportWidth / 2, MainScrollViewer.ViewportHeight / 2);
                    lastCenterPositionOnTarget = MainScrollViewer.TranslatePoint(centerOfViewport1, GridWorkspace);
                }
                else
                {
                    lb.IsEnabled = false;
                }
                break;
            }
            lbZoomRatio.Content = (Zoom * 100).ToString() + "%";
        }
Пример #16
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);
            }
        }
Пример #17
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);
                }
            }
        }
 /// <summary>
 /// Add message to UI
 /// </summary>
 /// <param name="message">The message to add</param>
 public void AddMessage(ChatMessagesNotify message)
 {
     _lastMessageIndex++; //TODO: Will this make some problems when the message is not sent?
     Application.Current.Dispatcher.Invoke(() => MessagesList.Add(message));
     if (!message.MyMessage)
     {
         _stopLoading = true;
         // scroll to bottom if needed
         MainScrollViewer.UpdateLayout();
         if (MainScrollViewer.ScrollableHeight - MainScrollViewer.VerticalOffset < 30)
         {
             MainScrollViewer.ScrollToBottom();
             MainScrollViewer.UpdateLayout();
         }
         _stopLoading = false;
     }
 }
Пример #19
0
        void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            string activeFilter = "";

            foreach (var i in FilterStrings)
            {
                if (SearchControl.Text == i + ":")
                {
                    activeFilter = i;
                }
            }

            if (activeFilter == "")
            {
                foreach (UIElement i in MainStackPanel.Children)
                {
                    if ((i as ISettingControl).Contains(SearchControl.Text))
                    {
                        i.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        i.Visibility = Visibility.Collapsed;
                    }
                }

                FilterListBox.SelectedItem = null;
            }
            else
            {
                foreach (UIElement i in MainStackPanel.Children)
                {
                    if ((i as ISettingControl).SettingBase.Filter == activeFilter)
                    {
                        i.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        i.Visibility = Visibility.Collapsed;
                    }
                }
            }

            MainScrollViewer.ScrollToTop();
        }
Пример #20
0
        private void MainControlsNewAdventureButton_Click(object sender, RoutedEventArgs e)
        {
            MainScrollViewer.Fade(0).Scale(0.5f, 0.5f, (float)MainScrollViewer.ActualWidth / 2, (float)MainScrollViewer.ActualHeight / 2).SetDuration(200).Start();
            MainScrollViewer.IsHitTestVisible = false;

            _title = MainControlsTitle.Text;
            MainControlsTitle.Text = "NEW ADVENTURE";

            FindName("CreateAdventureSection");
            CreateAdventureSection.Scale(1.2f, 1.2f, (float)ActualWidth / 2, (float)CreateAdventureSection.ActualHeight / 2, 0)
            .Then().Fade(1).Scale(1f, 1f, (float)ActualWidth / 2, (float)CreateAdventureSection.ActualHeight / 2, 0)
            .SetDuration(300).Start();
            CreateAdventureSection.IsHitTestVisible = true;

            (App.Current as App).BackRequested += HideCreateNewAdventureSection;
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            CreateAdventureTextBox.Focus(FocusState.Keyboard);
        }
Пример #21
0
        private void HideCreateNewAdventureSection(object sender, BackRequestedEventArgs e)
        {
            e.Handled = true;
            (App.Current as App).BackRequested -= HideCreateNewAdventureSection;
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                Frame.CanGoBack ?
                AppViewBackButtonVisibility.Visible :
                AppViewBackButtonVisibility.Collapsed;

            MainControlsTitle.Text = _title;

            MainScrollViewer.Fade(1).Scale(1f, 1f, (float)MainScrollViewer.ActualWidth / 2, (float)MainScrollViewer.ActualHeight / 2).SetDuration(300).Start();
            MainScrollViewer.IsHitTestVisible = true;

            CreateAdventureSection.Scale(1.2f, 1.2f, (float)CreateAdventureSection.ActualWidth / 2, (float)CreateAdventureSection.ActualHeight / 2)
            .Fade(0).SetDuration(200).Start();
            CreateAdventureSection.IsHitTestVisible = false;
        }
Пример #22
0
        private async Task ObtenerRespuestaBot()
        {
            string  ultimoMensaje = Mensajes.Last().Texto;
            Mensaje mensajeBot    = new Mensaje("Robot", "Procesando...");

            // Cada vez que el bot responda algo, hacer scroll hasta el final
            MainScrollViewer.ScrollToEnd();
            Mensajes.Add(mensajeBot);
            try
            {
                mensajeBot.Texto = await QnA.PreguntarAsync(ultimoMensaje);

                RespuestaRecibida = true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #23
0
        private void OnCategoriesListLoaded(object sender, RoutedEventArgs e)
        {
            // If there is a category selected already, we want the view to update
            // the scroll position to show it.
            if (_viewModel.SelectedAccessoryCategory != null)
            {
                // MainScrollViewer control holds both the hero images and categories,
                // so we need to find the offset of the selected category in
                // the parent ScrollViewer control.
                var container =
                    CategoriesList.ContainerFromItem(_viewModel.SelectedAccessoryCategory) as FrameworkElement;

                if (container != null)
                {
                    var focusedVisualTransform = container.TransformToVisual(MainScrollViewer);
                    var transformPoint         = focusedVisualTransform.TransformPoint(new Point(0, 0));

                    // Now adjust the scroll position.
                    MainScrollViewer.ChangeView(null, transformPoint.Y, null, true);
                }
            }
        }
Пример #24
0
 private void ViewCenter()
 {
     MainScrollViewer.ScrollToHorizontalOffset(MainCanvas.ActualWidth / 2 - 450);
 }
        /// <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;
            }
        }
Пример #26
0
 private void MainScrollViewer_DoMouseWheel(MouseWheelEventArgs e)
 {
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset - e.Delta);
 }
Пример #27
0
 private void UIElement_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
 {
     MainScrollViewer.ScrollToVerticalOffset(MainScrollViewer.VerticalOffset - e.Delta / 3);
 }
        private async void SendBtnClicked(object sender, RoutedEventArgs e)
        {
            string message = MessageTextBox.Text.Trim();

            // initialize file send
            if (string.IsNullOrWhiteSpace(message))
            {
                OpenFileDialog ofd = new OpenFileDialog {
                    Title = "Send File"
                };
                bool?result = ofd.ShowDialog();
                if (result.HasValue && result.Value)
                {
                    string key = (await SharedStuff.Database.Table <DatabaseHelper.Users>().Where(user => user.Username == Username)
                                  .FirstAsync()).Key;
                    // at first request a token
                    string id    = Guid.NewGuid().ToString();
                    var    msgUi = new ChatMessagesNotify
                    {
                        MyMessage = true,
                        Message   = Path.GetFileName(ofd.FileName),
                        FullDate  = DateTime.Now,
                        Type      = 1,
                        Sent      = 1,
                        FilePath  = ofd.FileName,
                        With      = Username
                    };
                    SharedStuff.PendingMessages.Add(id, msgUi);
                    // create json
                    string json = JsonConvert.SerializeObject(new JsonTypes.SendMessage
                    {
                        Type    = 2,
                        Id      = id,
                        Payload = new JsonTypes.SendMessagePayload
                        {
                            To      = Username,
                            Message = Path.GetFileName(ofd.FileName)
                        }
                    });
                    SharedStuff.Websocket.SendAsync(json, null);
                    AddMessage(msgUi);
                }
            }
            else
            {
                if (SharedStuff.Websocket.IsAlive)
                {
                    string id = Guid.NewGuid().ToString();
                    await Task.Run(() => SendMessage(message, id));

                    var msgUi = new ChatMessagesNotify
                    {
                        MyMessage = true,
                        Message   = message,
                        FullDate  = DateTime.Now,
                        Type      = 0,
                        Sent      = 1
                    };
                    AddMessage(msgUi);                          // add it to ui
                    SharedStuff.PendingMessages.Add(id, msgUi); // add message to pending messages
                }
                else
                {
                    var msgUi = new ChatMessagesNotify
                    {
                        MyMessage = true,
                        Message   = message,
                        FullDate  = DateTime.Now,
                        Type      = 0,
                        Sent      = 2
                    };
                    AddMessage(msgUi);
                }

                // finalizing UI
                MessageTextBox.Text = "";
                MessageTextBox.Focus();
                _stopLoading = true;
                MainScrollViewer.ScrollToBottom();
                MainScrollViewer.UpdateLayout();
                _stopLoading        = false;
                SendButtonIcon.Kind = PackIconKind.Attachment;
                SendButton.ToolTip  = "Send File";
            }
        }
Пример #29
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);
 }
        private async void MessageTextBox_OnKeyDown(object sender, KeyEventArgs e)
        {
            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                if (Keyboard.IsKeyDown(Key.Enter))
                {
                    string message = MessageTextBox.Text.Trim().TrimEnd(Environment.NewLine.ToCharArray());
                    // do not send the message if it's empty
                    if (string.IsNullOrWhiteSpace(message))
                    {
                        return;
                    }
                    if (SharedStuff.Websocket.IsAlive)
                    {
                        string id = Guid.NewGuid().ToString();
                        await Task.Run(() => SendMessage(message, id)); // send message over network

                        var msgUi = new ChatMessagesNotify
                        {
                            MyMessage = true,
                            Message   = message,
                            FullDate  = DateTime.Now,
                            Type      = 0,
                            Sent      = 1
                        };
                        AddMessage(msgUi);                          // add it to ui
                        SharedStuff.PendingMessages.Add(id, msgUi); // add message to pending messages
                    }
                    else
                    {
                        var msgUi = new ChatMessagesNotify
                        {
                            MyMessage = true,
                            Message   = message,
                            FullDate  = DateTime.Now,
                            Type      = 0,
                            Sent      = 2
                        };
                        AddMessage(msgUi);
                    }
                    // finalizing UI
                    MessageTextBox.Text = "";
                    MessageTextBox.Focus();
                    _stopLoading = true;
                    MainScrollViewer.ScrollToBottom();
                    MainScrollViewer.UpdateLayout();
                    _stopLoading        = false;
                    SendButtonIcon.Kind = PackIconKind.Attachment;
                    SendButton.ToolTip  = "Send File";
                }
            }
            if (string.IsNullOrWhiteSpace(MessageTextBox.Text)) // show attachment icon
            {
                SendButtonIcon.Kind = PackIconKind.Attachment;
                SendButton.ToolTip  = "Send File";
            }
            else
            {
                SendButtonIcon.Kind = PackIconKind.Send;
                SendButton.ToolTip  = "Send Message";
            }
        }