void OnCompositionTargetRendering(object sender, object args) { // Get the time once DateTime utc = DateTime.UtcNow; foreach (UIElement child in uniformGrid.Children) { TimeZoneClockViewModel viewModel = (child as FrameworkElement).DataContext as TimeZoneClockViewModel; string timeZoneKey = viewModel.TimeZoneKey; // Set the local time from the TimeZoneManager viewModel.DateTime = timeZoneManager.GetLocalTime(timeZoneKey, utc); } }
void OnApplicationSuspending(object sender, SuspendingEventArgs args) { appSettings.Clear(); for (int index = 0; index < uniformGrid.Children.Count; index++) { TimeZoneClock timeZoneClock = uniformGrid.Children[index] as TimeZoneClock; TimeZoneClockViewModel viewModel = timeZoneClock.DataContext as TimeZoneClockViewModel; string preface = index.ToString(); appSettings[preface + "Location"] = viewModel.Location; appSettings[preface + "TimeZoneKey"] = viewModel.TimeZoneKey; appSettings[preface + "Foreground"] = viewModel.ForegroundName; appSettings[preface + "Background"] = viewModel.BackgroundName; } }
async void OnDeleteMenuItem(IUICommand command) { TimeZoneClock timeZoneClock = command.Id as TimeZoneClock; TimeZoneClockViewModel viewModel = timeZoneClock.DataContext as TimeZoneClockViewModel; MessageDialog msgdlg = new MessageDialog("Delete clock from collection?", viewModel.Location); msgdlg.Commands.Add(new UICommand("OK")); msgdlg.Commands.Add(new UICommand("Cancel")); msgdlg.DefaultCommandIndex = 0; msgdlg.CancelCommandIndex = 1; IUICommand msgDlgCommand = await msgdlg.ShowAsync(); if (msgDlgCommand.Label == "OK") { uniformGrid.Children.Remove(command.Id as TimeZoneClock); } }