コード例 #1
0
        /// <summary>
        /// Hide info pop-up or cancel the task if it wasn't finished yet (prevent pop-up showing).
        /// </summary>
        private void HideInfoPopup()
        {
            showInfoPopupTaskToken?.Cancel();
            showInfoPopupTaskToken?.Dispose();
            showInfoPopupTaskToken = null;

            infoPopupWindow?.Close();
            infoPopupWindow = null;
        }
コード例 #2
0
        /// <summary>
        /// Show info pop-up and position it.
        /// </summary>
        private async void ShowInfoPopup(DataGridClause clause)
        {
            Rect workArea = ScreenInfo.GetRectInDpi(this, ScreenInfo.GetScreenFrom(this).WorkingAreaPix);

            var popup = new InfoPopup(clause)
            {
                Owner = this
            };

            //Calculate shifts to position the pop-up relative to the main window and its screen

            double addX = (WindowState == WindowState.Normal)
                ? Left +
                          SystemParameters.WindowResizeBorderThickness.Left +
                          SystemParameters.WindowNonClientFrameThickness.Left
                : workArea.Left;

            double addY = (WindowState == WindowState.Normal)
                ? Top +
                          SystemParameters.WindowResizeBorderThickness.Top +
                          SystemParameters.WindowNonClientFrameThickness.Top
                : workArea.Top + SystemParameters.WindowCaptionHeight;


            popup.Show(); //Here, to get actual window size


            //Position the window

            popup.Left = Mouse.GetPosition(this).X - popup.Width / 2 + addX;
            popup.Top  = Mouse.GetPosition(this).Y - popup.Height + 5 + addY;


            //Handling of falling the window out of bounds of the screen

            if (popup.Left < workArea.Left)
            {
                popup.Left = workArea.Left;
            }
            else if ((popup.Left + popup.Width) > workArea.Right)
            {
                popup.Left = workArea.Right - popup.Width;
            }

            if (popup.Top < workArea.Top)
            {
                popup.Top = workArea.Top;
            }
            else if ((popup.Top + popup.Height) > workArea.Bottom)
            {
                popup.Top = workArea.Bottom - popup.Height;
            }

            infoPopupWindow = popup; //To make it thread safe


            if (PrgSettings.Default.AutoplaySound && !String.IsNullOrEmpty(clause.Sound))
            {
                try { await SoundManager.PlaySoundAsync(clause.Id, clause.Sound, dbFacade.DataSource); }
                catch (FileNotFoundException) { }
            }

            //Update clause's watch data
            if (clause.Watched.Date == DateTime.Now.Date)
            {
                return; //Increment only once a day
            }
            await dbFacade.UpdateClauseWatchAsync(clause.Id);

            DataGridClause updated = (await dbFacade.GetClauseByIdAsync(clause.Id)).MapToDataGridClause();

            clause.Watched      = updated.Watched;
            clause.WatchedCount = updated.WatchedCount;

            mainDataGrid.Items.Refresh();
        }