/// <summary> /// Show info pop-up with the certain delay. /// </summary> /// <param name="clause">The clause which info should be shown.</param> /// <returns>The task which will show the pop-up.</returns> private Task StartCountdownForInfoPopup(DataGridClause clause) { HideInfoPopup(); var cts = new CancellationTokenSource(); var ret = Task.Delay(1000, cts.Token) .ContinueWith(delayTask => { if (!delayTask.IsCanceled && infoPopupPivotCell?.IsMouseOver == true) { Dispatcher.Invoke(() => ShowInfoPopup(clause)); } }); showInfoPopupTaskToken = cts; //To make it thread safe return(ret); }
private async void OnCreateButton_Click(object sender, RoutedEventArgs e) { for (int i = words.Length - 1; i > 0; i--) { DataGridClause first = words[i]; for (int j = i - 1; j >= 0; j--) { DataGridClause second = words[j]; await dbFacade.AddOrUpdateRelationAsync(0, first.Id, second.Id, newRelationDescrTBox.Text); await dbFacade.AddOrUpdateRelationAsync(0, second.Id, first.Id, newRelationDescrTBox.Text); } } DialogResult = true; Close(); }
/// <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(); }
public InfoPopup(DataGridClause clause) { if (clause is null) { throw new ArgumentNullException(nameof(clause)); } InitializeComponent(); ApplyGUIScale(); this.clause = clause; groupLbl.Content = clause.Group.ToFullStr(); wordLbl.Content = clause.Word; translationsLbl.Content = clause.Translations; asteriskLbl.Content = clause.AsteriskType != AsteriskType.None ? $"✶ {clause.AsteriskType.ToShortStr()}" : ""; dateLbl.Content = String.Format(Properties.Resources.WatchedDateCount, clause.Watched, clause.WatchedCount); if (String.IsNullOrEmpty(clause.Transcription)) { transcriptionLbl.Visibility = Visibility.Hidden; } else { transcriptionLbl.Content = $"[{clause.Transcription}]"; } if (clause.HasRelations) { Clause cl = dbFacade.GetClauseByIdAsync(clause.Id).Result; Debug.Assert(cl != null); int maxCount = 10; foreach (Relation rl in cl.Relations) { var copy = (FrameworkElement)XamlReader.Parse(XamlWriter.Save(relTemplatePanel)); copy.Name = null; //To show that it's a new item copy.Visibility = Visibility.Visible; copy.ToolTip = ClauseToDataGridClauseMapper.MakeTranslationsString( dbFacade.GetClauseByIdAsync(rl.ToClause.Id).Result.Translations); if (PrgSettings.Default.AutoplaySound && !String.IsNullOrEmpty(rl.ToClause.Sound)) { copy.ToolTipOpening += async(s, e) => await SoundManager.PlaySoundAsync(rl.ToClause.Id, rl.ToClause.Sound, dbFacade.DataSource); } var newWordLbl = (Label)copy.FindName(nameof(relationLbl)); newWordLbl.Content = rl.ToClause.Word; var newDescriptionLbl = (Label)copy.FindName(nameof(descriptionLbl)); newDescriptionLbl.Content = $" - {rl.Description}"; mainPanel.Children.Insert(mainPanel.Children.IndexOf(relTemplatePanel), copy); if (--maxCount == 0) { break; } } } relTemplatePanel.Visibility = Visibility.Hidden; relTemplatePanel.Height = 0; //To correct row height }