Browse Source

Add tutorial on writing a custom format and remove some lesser used ones

Daniel Chalmers 1 year ago
parent
commit
55a08bba63
3 changed files with 27 additions and 5 deletions
  1. 3 5
      DesktopClock/DateFormatExample.cs
  2. 6 0
      DesktopClock/MainWindow.xaml
  3. 18 0
      DesktopClock/MainWindow.xaml.cs

+ 3 - 5
DesktopClock/DateFormatExample.cs

@@ -15,6 +15,8 @@ public record DateFormatExample
     public string Format { get; }
     public string Example { get; }
 
+    public static DateFormatExample Tutorial => new("", "Create my own format...");
+
     /// <summary>
     /// Creates a <see cref="DateFormatExample" /> from the given format.
     /// </summary>
@@ -34,10 +36,6 @@ public record DateFormatExample
         "dddd, MMM dd, hh:mm tt",
         "dddd, MMM dd, HH:mm:ss",
         "dddd, MMM dd, hh:mm:ss tt",
-        "ddd, MMMM dd, HH:mm",
-        "ddd, MMMM dd, hh:mm tt",
-        "ddd, MMMM dd, HH:mm:ss",
-        "ddd, MMMM dd, hh:mm:ss tt",
         "ddd, MMM dd, HH:mm",
         "ddd, MMM dd, hh:mm tt",
         "ddd, MMM dd, HH:mm:ss",
@@ -50,5 +48,5 @@ public record DateFormatExample
         "t",
         "T",
         "O",
-    }.Select(FromFormat).ToList();
+    }.Select(FromFormat).Append(Tutorial).ToList();
 }

+ 6 - 0
DesktopClock/MainWindow.xaml

@@ -91,6 +91,12 @@
 			<MenuItem Header="_Format" ItemsSource="{x:Static local:DateFormatExample.DefaultExamples}">
 				<MenuItem.Resources>
 					<Style TargetType="MenuItem">
+						<Style.Triggers>
+							<DataTrigger Binding="{Binding}" Value="{x:Static local:DateFormatExample.Tutorial}">
+								<Setter Property="Command" Value="{Binding DataContext.FormatWizardCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
+							</DataTrigger>
+						</Style.Triggers>
+
 						<Setter Property="Command" Value="{Binding DataContext.SetFormatCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
 
 						<Setter Property="CommandParameter" Value="{Binding Format}" />

+ 18 - 0
DesktopClock/MainWindow.xaml.cs

@@ -71,6 +71,24 @@ public partial class MainWindow : Window
     [RelayCommand]
     public void SetFormat(string format) => Settings.Default.Format = format;
 
+    /// <summary>
+    /// Explains how to write a format, then asks user if they want to view a website and Advanced settings to do so.
+    /// </summary>
+    [RelayCommand]
+    public void FormatWizard()
+    {
+        var result = MessageBox.Show(this,
+            $"In advanced settings: edit \"{nameof(Settings.Default.Format)}\" using special \"Custom date and time format strings\", then save." +
+            "\n\nOpen advanced settings and a tutorial now?",
+            Title, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.OK);
+
+        if (result != MessageBoxResult.OK)
+            return;
+
+        Process.Start("https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings");
+        OpenSettings();
+    }
+
     /// <summary>
     /// Sets time zone ID in settings to given time zone ID.
     /// </summary>