-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathApp.cs
More file actions
234 lines (216 loc) · 7.53 KB
/
App.cs
File metadata and controls
234 lines (216 loc) · 7.53 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using Microsoft.UI.Reactor;
using Microsoft.UI.Reactor.Core;
using Microsoft.UI.Xaml.Controls;
using static Microsoft.UI.Reactor.Factories;
using Microsoft.UI.Xaml;
ReactorApp.Run<DialogsAndFlyoutsApp>("Dialogs and Flyouts", width: 640, height: 960
#if DEBUG
, preview: true
#endif
);
// <snippet:basic-dialog>
class BasicDialogDemo : Component
{
public override Element Render()
{
var (open, setOpen) = UseState(false);
return VStack(8,
SubHeading("Basic ContentDialog"),
Button("Show dialog", () => setOpen(true)),
// Dialog lives in the tree at all times. IsOpen controls
// visibility; OnClosed flips it back when the user dismisses.
ContentDialog(
"Welcome",
TextBlock("Thank you for trying Reactor."),
primaryButtonText: "OK") with
{
IsOpen = open,
OnClosed = _ => setOpen(false),
}
).Padding(24);
}
}
// </snippet:basic-dialog>
// <snippet:confirm-dialog>
class ConfirmDialogDemo : Component
{
public override Element Render()
{
var (open, setOpen) = UseState(false);
var (result, setResult) = UseState("(none)");
return VStack(8,
SubHeading("Confirmation with three buttons"),
Button("Delete item…", () => setOpen(true)),
TextBlock($"Last result: {result}").Opacity(0.6),
ContentDialog(
"Delete this item?",
TextBlock("This action cannot be undone."),
primaryButtonText: "Delete") with
{
IsOpen = open,
SecondaryButtonText = "Cancel",
CloseButtonText = "Close",
DefaultButton = ContentDialogButton.Close,
OnClosed = r =>
{
setResult(r.ToString());
setOpen(false);
},
}
).Padding(24);
}
}
// </snippet:confirm-dialog>
// <snippet:dialog-gated-primary>
class DialogGatedPrimaryDemo : Component
{
public override Element Render()
{
var (open, setOpen) = UseState(false);
var (name, setName) = UseState("");
return VStack(8,
SubHeading("Primary disabled until input is valid"),
Button("Rename file…", () => setOpen(true)),
ContentDialog(
"Rename file",
VStack(8,
TextBlock("New filename:"),
TextBox(name, setName, placeholder: "untitled.txt")
.Width(280)),
primaryButtonText: "Rename") with
{
IsOpen = open,
SecondaryButtonText = "Cancel",
// .IsPrimaryButtonEnabled drives the inline primary
// disabled state without taking it out of tab order.
IsPrimaryButtonEnabled = !string.IsNullOrWhiteSpace(name),
OnClosed = _ => setOpen(false),
}
).Padding(24);
}
}
// </snippet:dialog-gated-primary>
// <snippet:menu-flyout>
class MenuFlyoutDemo : Component
{
public override Element Render()
{
var (action, setAction) = UseState("(none)");
return VStack(8,
SubHeading("MenuFlyout — right-click or button-click"),
MenuFlyout(
Button("Edit ▾"),
MenuItem("Cut", () => setAction("Cut"), icon: "Cut"),
MenuItem("Copy", () => setAction("Copy"), icon: "Copy"),
MenuItem("Paste", () => setAction("Paste"), icon: "Paste"),
MenuSeparator(),
MenuSubItem("Format",
ToggleMenuItem("Bold", isChecked: false),
ToggleMenuItem("Italic", isChecked: true)),
MenuSeparator(),
MenuItem("Delete…", () => setAction("Delete"))
),
TextBlock($"Last action: {action}").Opacity(0.6)
).Padding(24);
}
}
// </snippet:menu-flyout>
// <snippet:command-bar-flyout>
class CommandBarFlyoutDemo : Component
{
public override Element Render()
{
var (action, setAction) = UseState("(none)");
return VStack(8,
SubHeading("CommandBarFlyout"),
CommandBarFlyout(
Button("Selection ▾"),
primaryCommands: new AppBarItemBase[]
{
AppBarButton("Cut", () => setAction("Cut"), icon: "Cut"),
AppBarButton("Copy", () => setAction("Copy"), icon: "Copy"),
AppBarButton("Paste", () => setAction("Paste"), icon: "Paste"),
},
secondaryCommands: new AppBarItemBase[]
{
AppBarButton("Select All", () => setAction("Select All")),
AppBarButton("Find", () => setAction("Find")),
}),
TextBlock($"Last action: {action}").Opacity(0.6)
).Padding(24);
}
}
// </snippet:command-bar-flyout>
// <snippet:popup>
class PopupDemo : Component
{
public override Element Render()
{
var (open, setOpen) = UseState(false);
// Popup is a free-form positioned surface. Use it for overlays
// that aren't dialogs or flyouts — color pickers, in-place
// editors, custom tooltips.
var popupContent = Border(
VStack(8,
TextBlock("This is a Popup.").Bold(),
TextBlock("Click outside to dismiss.")
).Padding(12)
).Background("#FFFFFF").WithBorder("#888888").CornerRadius(6);
return VStack(8,
SubHeading("Popup"),
Button(open ? "Hide popup" : "Show popup",
() => setOpen(!open)),
Popup(popupContent, isOpen: open,
onClosed: () => setOpen(false))
.IsLightDismissEnabled()
.Offset(120, 0)
).Padding(24);
}
}
// </snippet:popup>
// <snippet:commanding-integration>
class CommandingIntegrationDemo : Component
{
public override Element Render()
{
// One Command drives the button, the menu item, and (via
// .Accelerator) Ctrl+S. The same Command can light up an
// AppBarButton in a CommandBarFlyout too — same declaration,
// three surfaces.
var (saved, setSaved) = UseState(false);
var save = new Command
{
Label = "Save",
Execute = () => setSaved(true),
CanExecute = !saved,
Icon = SymbolIcon("Save"),
};
return VStack(8,
SubHeading("One Command, two surfaces"),
Button(save), // primary CTA
MenuFlyout(
Button("File ▾"),
MenuItem(save), // menu duplicate
MenuSeparator(),
MenuItem("Reset", () => setSaved(false))),
TextBlock(saved ? "Saved." : "Unsaved changes.")
.Opacity(0.6)
).Padding(24);
}
}
// </snippet:commanding-integration>
class DialogsAndFlyoutsApp : Component
{
public override Element Render() => ScrollView(
VStack(24,
Heading("Dialogs and Flyouts"),
Component<BasicDialogDemo>(),
Component<ConfirmDialogDemo>(),
Component<DialogGatedPrimaryDemo>(),
Component<MenuFlyoutDemo>(),
Component<CommandBarFlyoutDemo>(),
Component<PopupDemo>(),
Component<CommandingIntegrationDemo>()
).Padding(24)
);
}