public EntryDetails() { InitializeComponent(); // update the time on this window Task.Factory.StartNew(() => { while (true) { Thread.Sleep(1000); this.Dispatcher.Invoke(() => { if (this.Visibility != Visibility.Visible) { return; // don't update if this window is hidden } if (CurrentTime.IsSelectionActive) { return; // don't update as the user is typing } if (SelectedTimeEntry == null) { return; // (potential) null exception } decimal hours = decimal.Parse(SelectedTimeEntry.ToView(0).Hours) + PendingOffset; CurrentTime.Text = hours.ToString(); }); } }); }
private void AddTime_Click(object sender, RoutedEventArgs e) { // Ironically I don't have time to think of a proper solution for adjusting // the time of an entry. // Since the total duration is calculated each time, we can use a variable offset. if (this.popup != null) { this.popup.Close(); this.popup = null; } this.popup = new EditTime(); popup.ParentWindow = this; popup.SelectedTimeEntry = SelectedTimeEntry; // pending to be saved / tentative changes applied decimal pendingHours = decimal.Parse(SelectedTimeEntry.ToView(0).Hours) + PendingOffset; popup.NewHours.Text = pendingHours.ToString(); popup.Show(); popup.Focus(); popup.NewHours.Focus(); popup.NewHours.SelectAll(); }
private void ApplyNewTime() { decimal currentHours = decimal.Parse(SelectedTimeEntry.ToView(0).Hours) + ParentWindow.PendingOffset; if (!decimal.TryParse(NewHours.Text, out decimal newTimeInHours)) { NewHours.Text = currentHours.ToString(); return; } // careful not to accidentally change the source data // i.e. still allow the user to cancel later ParentWindow.PendingOffset += newTimeInHours - currentHours; //ParentWindow.CurrentTime.Text = newTimeInHours.ToString(); this.Close(); }