-
Notifications
You must be signed in to change notification settings - Fork 16
/
MainWindow.axaml.cs
79 lines (69 loc) · 2.7 KB
/
MainWindow.axaml.cs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using CSharpEditor;
namespace CSharpEditorIPCDemoClient
{
public class MainWindow : Window
{
// Do not run this program directly. Let it be started by the CSharpEditorIPCDemoServer.
// This will be set to true when the parent process exits, to signal that this process also needs to die.
bool terminating = false;
public MainWindow()
{
InitializeComponent();
// Set up the client debugger, passing the arguments that were used to start the program.
InterprocessDebuggerClient client = new InterprocessDebuggerClient(Program.CallingArguments);
this.Content = client;
// This event is called when a breakpoint in the code is hit. We show this window, so that users can
// interact with it.
client.BreakpointHit += (s, e) =>
{
this.Show();
this.Activate();
};
// This event is invoked when the user has clicked on the button to resume code execution after the
// breakpoint.
client.BreakpointResumed += (s, e) =>
{
this.Hide();
};
// This event is called when the parent process that started this program exits.
client.ParentProcessExited += (s, e) =>
{
// Signals that the window needs to be closed.
terminating = true;
this.Close();
};
// Prevent this window from actually closing, unless the parent process has already exited.
this.Closing += (s, e) =>
{
if (!terminating)
{
e.Cancel = true;
this.Hide();
}
};
}
// This will be set to true after the first time this window is shown.
bool initialized = false;
public override void Show()
{
if (!initialized)
{
initialized = true;
// Hide the window just after it is shown. We can't just not show the window, otherwise the first time it is shown it will be below the window of the server process.
// Still, this is not 100% fail-proof, as sometimes the Activate method does not work properly.
base.Show();
this.Hide();
}
else
{
base.Show();
}
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}