-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
63 lines (57 loc) · 1.98 KB
/
App.xaml.cs
File metadata and controls
63 lines (57 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Ookii.CommandLine;
using Ookii.Dialogs.Wpf;
using System.Windows;
namespace WpfSample;
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// Use the CommandLineParser<T> class, instead of the static Parse() method, so we can
// manually handle errors. The GeneratedParserAttribute generates a CreateParser() method
// for this purpose.
var parser = Arguments.CreateParser();
try
{
var args = parser.Parse(e.Args);
if (args != null)
{
// Arguments were parsed successfully.
var window = new MainWindow(args);
window.Show();
return;
}
}
catch (CommandLineArgumentException ex)
{
// Use a TaskDialog (from Ookii.Dialogs) so we can have a help button.
var dialog = new TaskDialog()
{
MainInstruction = "Invalid command line",
Content = ex.Message,
WindowTitle = parser.ApplicationFriendlyName,
MainIcon = TaskDialogIcon.Error,
AllowDialogCancellation = true,
};
dialog.Buttons.Add(new TaskDialogButton(ButtonType.Close) { Default = true });
var helpButton = new TaskDialogButton("&Help");
dialog.Buttons.Add(helpButton);
var button = dialog.Show();
// Don't show help unless the help button was used.
if (button != helpButton)
{
parser.HelpRequested = false;
}
}
if (parser.HelpRequested)
{
var help = new UsageWindow(parser);
help.Show();
return;
}
// Need to shutdown manually if we didn't show any window.
Shutdown();
}
}