Repository navigation
Expand file tree
/
Copy pathOneWayBindingExamples.cs
More file actions
639 lines (505 loc) · 25.7 KB
/
Copy pathOneWayBindingExamples.cs
File metadata and controls
639 lines (505 loc) · 25.7 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
// Copyright (c) ReactiveUI and Contributors. All rights reserved.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System.Globalization;
using ReactiveUI.Binding.Builder;
using ReactiveUI.Binding.Documentation.Banking;
using ReactiveUI.Binding.Documentation.CloudStorage;
using ReactiveUI.Binding.Documentation.GitHub;
using ReactiveUI.Binding.Documentation.Todo;
using ReactiveUI.Primitives.Concurrency;
namespace ReactiveUI.Binding.Documentation.Bindings;
/// <summary>Shows how <c>BindOneWay</c> and <c>OneWayBind</c> copy a view model property onto a view property.</summary>
public static class OneWayBindingExamples
{
/// <summary>The size of the file the upload example sends: four 4 MiB parts.</summary>
private const long UploadSizeBytes = 16_777_216;
/// <summary>The number that turns an upload percentage into the fraction a progress bar shows.</summary>
private const double PercentPerBar = 100D;
/// <summary>The position of the checkout issue in the list of open issues, which is newest first.</summary>
private const int CheckoutIssueIndex = 1;
/// <summary>The account name of the person the checkout issue is reassigned to.</summary>
private const string ReassignedLogin = "tomas-berg";
/// <summary>The balance the everyday account holds after a deposit.</summary>
private const decimal DepositedBalance = 1200.50M;
/// <summary>The number format that groups digits and shows no decimals.</summary>
private const string GroupedFormat = "N0";
/// <summary>The number format that shows one decimal place.</summary>
private const string OneDecimalFormat = "N1";
/// <summary>The hint that asks the priority converter for its dark palette.</summary>
private const string DarkThemeHint = "dark";
/// <summary>The text of the filter the customer types.</summary>
private const string CarFilter = "car";
/// <summary>The text shown for an open issue.</summary>
private const string OpenText = "Open";
/// <summary>The text shown for a closed issue.</summary>
private const string ClosedText = "Closed";
/// <summary>The title of the to-do item whose priority the badge examples show.</summary>
private const string ItemTitle = "Renew car registration";
/// <summary>The text shown when no issue is selected.</summary>
private const string NothingSelectedText = "nothing selected";
/// <summary>The time a sequencer stands still before it runs the writes that wait for it.</summary>
private static readonly TimeSpan NextTurn = TimeSpan.FromMilliseconds(1);
/// <summary>Registers the core services the <c>Unsafe</c> bindings look up while the app runs.</summary>
public static void BuildApplication()
{
IReactiveUIBindingBuilder builder = RxBindingBuilder.CreateReactiveUIBindingBuilder();
_ = builder.WithCoreServices().BuildApp();
}
/// <summary>Copies one property to another of the same type with <c>BindOneWay</c>.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindSelectedIssueTitleToLabel()
{
IssueBoardViewModel board = await OpenIssueBoardAsync();
IssueBoardView view = new();
using (board.BindOneWay(view, static x => x.SelectedIssue!.Title, static v => v.IssueTitleLabel.Text))
{
// The path passes through SelectedIssue, which is null until the user picks an issue.
Console.WriteLine(view.IssueTitleLabel.Text ?? NothingSelectedText);
board.SelectedIssue = board.Issues[CheckoutIssueIndex];
Console.WriteLine(view.IssueTitleLabel.Text);
board.SelectedIssue = board.Issues[0];
Console.WriteLine(view.IssueTitleLabel.Text);
}
// Output:
// nothing selected
// Checkout button unresponsive on Safari
// Add gift-card support
}
/// <summary>Follows a path through an optional property: an issue without an assignee has no login to show.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindSelectedIssueAssigneeToLabel()
{
IssueBoardViewModel board = await OpenIssueBoardAsync();
IssueBoardView view = new();
using (board.BindOneWay(view, static x => x.SelectedIssue!.Assignee!.Login, static v => v.AssigneeLabel.Text))
{
board.SelectedIssue = board.Issues[CheckoutIssueIndex];
Console.WriteLine(view.AssigneeLabel.Text);
board.SelectedIssue.Assignee = new User { Login = ReassignedLogin, DisplayName = "Tomas Berg" };
Console.WriteLine(view.AssigneeLabel.Text);
board.SelectedIssue = board.Issues[0];
Console.WriteLine(view.AssigneeLabel.Text ?? NothingSelectedText);
}
// Output:
// priya-nair
// tomas-berg
// nothing selected
}
/// <summary>Turns an enum into text with a converter function, the second <c>BindOneWay</c> overload.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindSelectedIssueStateToLabel()
{
IssueBoardViewModel board = await OpenIssueBoardAsync();
IssueBoardView view = new();
using (board.BindOneWay(view, static x => x.SelectedIssue!.State, static v => v.StateLabel.Text, static state => state == IssueState.Open ? OpenText : ClosedText))
{
board.SelectedIssue = board.Issues[CheckoutIssueIndex];
Console.WriteLine(view.StateLabel.Text);
board.SelectedIssue.State = IssueState.Closed;
Console.WriteLine(view.StateLabel.Text);
}
// Output:
// Open
// Closed
}
/// <summary>Shows how many to-do items are left, and stops updating once the binding is disposed.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindRemainingCountToLabel()
{
TodoListViewModel list = await OpenTodoListAsync();
TodoView view = new();
using (list.BindOneWay(view, static x => x.RemainingCount, static v => v.RemainingLabel.Text, static count => count.ToString(CultureInfo.InvariantCulture)))
{
Console.WriteLine(view.RemainingLabel.Text);
list.SelectedItem = list.Items[0];
await list.CompleteAsync();
Console.WriteLine(view.RemainingLabel.Text);
}
// Disposing the binding disconnects it: the label keeps the last text it was given.
list.SelectedItem = list.Items[CheckoutIssueIndex];
await list.CompleteAsync();
Console.WriteLine(view.RemainingLabel.Text);
// Output:
// 3
// 2
// 2
}
/// <summary>Formats a balance as currency with a converter function.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindBalanceToLabelWithCurrencyFormat()
{
AccountsViewModel accounts = await OpenAccountsAsync();
AccountsView view = new();
using (accounts.BindOneWay(view, static x => x.SelectedAccount!.Balance, static v => v.BalanceLabel.Text, FormatBalance))
{
accounts.SelectedAccount = accounts.Accounts[0];
Console.WriteLine(view.BalanceLabel.Text);
accounts.SelectedAccount.Balance = DepositedBalance;
Console.WriteLine(view.BalanceLabel.Text);
accounts.SelectedAccount = accounts.Accounts[1];
Console.WriteLine(view.BalanceLabel.Text);
}
// Output:
// A$2,450.75
// A$1,200.50
// A$15,230.00
}
/// <summary>Copies the filter text of the to-do list into the filter box with the view-first <c>OneWayBind</c>.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task OneWayBindFilterTextToBox()
{
TodoListViewModel list = await OpenTodoListAsync();
TodoView view = new() { ViewModel = list };
using (view.OneWayBind(list, static x => x.FilterText, static v => v.FilterTextBox.Text))
{
list.FilterText = CarFilter;
Console.WriteLine(view.FilterTextBox.Text);
}
// Output:
// car
}
/// <summary>Binds into a named control, which markup declares as a field, with the view-first <c>OneWayBind</c>.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task OneWayBindIntoNamedControl()
{
TodoListViewModel list = await OpenTodoListAsync();
TodoHeadingView view = new() { ViewModel = list };
// TitleLabel is a field, like every x:Name control; the path runs through it.
using (view.OneWayBind(list, static x => x.SelectedItem!.Title, static v => v.TitleLabel.Text))
{
list.SelectedItem = list.Items[0];
Console.WriteLine(view.TitleLabel.Text);
list.SelectedItem = list.Items[1];
Console.WriteLine(view.TitleLabel.Text);
}
// Output:
// Renew car registration
// Book dentist appointment
}
/// <summary>Keeps the label as it is while the path to the bound property passes through a null.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task OneWayBindKeepsViewWhilePathIsBroken()
{
TodoListViewModel list = await OpenTodoListAsync();
TodoHeadingView view = new() { ViewModel = list };
using (view.OneWayBind(list, static x => x.SelectedItem!.Title, static v => v.TitleLabel.Text))
{
// Nothing is selected yet, so there is no title to write and the label is left alone.
Console.WriteLine(view.TitleLabel.Text ?? NothingSelectedText);
list.SelectedItem = list.Items[0];
Console.WriteLine(view.TitleLabel.Text);
// Clearing the selection breaks the path again; the label keeps the last title it was given.
list.SelectedItem = null;
Console.WriteLine(view.TitleLabel.Text);
}
// Output:
// nothing selected
// Renew car registration
// Renew car registration
}
/// <summary>Fills a progress bar from the upload percentage with a selector that turns a percentage into the fraction the bar shows.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task OneWayBindUploadPercentToProgressBar()
{
StorageBrowserViewModel browser = await OpenBucketAsync();
StorageBrowserView view = new() { ViewModel = browser };
// A view-first binding reads its view model from the view's ViewModel property.
using (view.OneWayBind(browser, static x => x.UploadPercent, static v => v.UploadProgressBar.Progress, static percent => percent / PercentPerBar))
{
Console.WriteLine(view.UploadProgressBar.Progress);
await browser.UploadAsync(new("launch-video.mp4", UploadSizeBytes, "video/mp4"));
Console.WriteLine(view.UploadProgressBar.Progress);
}
// Output:
// 0
// 1
}
/// <summary>Formats a balance for a label with a selector, the second <c>OneWayBind</c> overload.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task OneWayBindAvailableBalanceWithSelector()
{
AccountsViewModel accounts = await OpenAccountsAsync();
AccountsView view = new() { ViewModel = accounts };
using (view.OneWayBind(accounts, static x => x.SelectedAccount!.AvailableBalance, static v => v.AvailableBalanceLabel.Text, FormatBalance))
{
accounts.SelectedAccount = accounts.Accounts[0];
// The everyday account has a 500 overdraft on top of its balance.
Console.WriteLine(view.AvailableBalanceLabel.Text);
}
// Output:
// A$2,950.75
}
/// <summary>Names the sequencer that delivers the write; the write waits until the sequencer runs.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindOneWayOnSequencer()
{
IssueBoardViewModel board = await OpenIssueBoardAsync();
IssueBoardView view = new();
VirtualClock uiThread = new();
using (board.BindOneWay(view, static x => x.SelectedIssue!.Title, static v => v.IssueTitleLabel.Text, uiThread))
{
board.SelectedIssue = board.Issues[CheckoutIssueIndex];
Console.WriteLine($"Waiting: '{view.IssueTitleLabel.Text}'");
uiThread.AdvanceBy(NextTurn);
Console.WriteLine($"Written: '{view.IssueTitleLabel.Text}'");
}
// Output:
// Waiting: ''
// Written: 'Checkout button unresponsive on Safari'
}
/// <summary>Converts with a function and delivers on a named sequencer.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindOneWayConvertedOnSequencer()
{
TodoListViewModel list = await OpenTodoListAsync();
TodoView view = new();
VirtualClock uiThread = new();
using (list.BindOneWay(view, static x => x.RemainingCount, static v => v.RemainingLabel.Text, static count => count.ToString(CultureInfo.InvariantCulture), uiThread))
{
Console.WriteLine($"Waiting: '{view.RemainingLabel.Text}'");
uiThread.AdvanceBy(NextTurn);
Console.WriteLine($"Written: '{view.RemainingLabel.Text}'");
}
// Output:
// Waiting: ''
// Written: '3'
}
/// <summary>Converts with a converter object. Without a hint <see cref="CurrencyTextConverter"/> shows two decimal places.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindOneWayWithConverterObject()
{
AccountsViewModel accounts = await OpenAccountsAsync();
AccountsView view = new();
using (accounts.BindOneWay(view, static x => x.TotalBalance, static v => v.TotalBalanceLabel.Text, new CurrencyTextConverter()))
{
Console.WriteLine(view.TotalBalanceLabel.Text);
}
// Output:
// $17,680.75
}
/// <summary>Passes a hint to the converter: the hint is the number format the total is shown in.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindOneWayWithConverterObjectAndHint()
{
AccountsViewModel accounts = await OpenAccountsAsync();
AccountsView view = new();
using (accounts.BindOneWay(view, static x => x.TotalBalance, static v => v.TotalBalanceLabel.Text, new CurrencyTextConverter(), GroupedFormat))
{
Console.WriteLine(view.TotalBalanceLabel.Text);
}
// Output:
// $17,681
}
/// <summary>Passes a converter object, a hint and a named sequencer.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindOneWayWithConverterObjectOnSequencer()
{
AccountsViewModel accounts = await OpenAccountsAsync();
AccountsView view = new();
VirtualClock uiThread = new();
using (accounts.BindOneWay(view, static x => x.TotalBalance, static v => v.TotalBalanceLabel.Text, new CurrencyTextConverter(), GroupedFormat, uiThread))
{
Console.WriteLine($"Waiting: '{view.TotalBalanceLabel.Text}'");
uiThread.AdvanceBy(NextTurn);
Console.WriteLine($"Written: '{view.TotalBalanceLabel.Text}'");
}
// Output:
// Waiting: ''
// Written: '$17,681'
}
/// <summary>Colours a badge from the priority of a to-do item with a converter object in the view-first <c>OneWayBind</c>.</summary>
public static void OneWayBindPriorityToBadgeColour()
{
TodoItem item = new() { Title = ItemTitle, Priority = TodoPriority.High };
TodoItemBadgeView view = new() { ViewModel = item };
using (view.OneWayBind(item, static x => x.Priority, static v => v.PriorityBadge.Color, new PriorityColourConverter()))
{
Console.WriteLine(view.PriorityBadge.Color.ToArgbHex());
item.Priority = TodoPriority.Low;
Console.WriteLine(view.PriorityBadge.Color.ToArgbHex());
}
// Output:
// #C62828
// #2E7D32
}
/// <summary>Passes the dark-theme hint to the priority converter.</summary>
public static void OneWayBindPriorityToBadgeColourWithHint()
{
TodoItem item = new() { Title = ItemTitle, Priority = TodoPriority.High };
TodoItemBadgeView view = new() { ViewModel = item };
using (view.OneWayBind(item, static x => x.Priority, static v => v.PriorityBadge.Color, new PriorityColourConverter(), DarkThemeHint))
{
Console.WriteLine(view.PriorityBadge.Color.ToArgbHex());
item.Priority = TodoPriority.Normal;
Console.WriteLine(view.PriorityBadge.Color.ToArgbHex());
}
// Output:
// #EF5350
// #BDBDBD
}
/// <summary>Passes the converter object, the hint and a named sequencer to <c>OneWayBind</c>.</summary>
public static void OneWayBindPriorityToBadgeColourOnSequencer()
{
TodoItem item = new() { Title = ItemTitle, Priority = TodoPriority.High };
TodoItemBadgeView view = new() { ViewModel = item };
VirtualClock uiThread = new();
using (view.OneWayBind(item, static x => x.Priority, static v => v.PriorityBadge.Color, new PriorityColourConverter(), DarkThemeHint, uiThread))
{
Console.WriteLine($"Waiting: '{view.PriorityBadge.Color?.ToArgbHex()}'");
uiThread.AdvanceBy(NextTurn);
Console.WriteLine($"Written: '{view.PriorityBadge.Color?.ToArgbHex()}'");
}
// Output:
// Waiting: ''
// Written: '#EF5350'
}
/// <summary>Formats with a selector and delivers the write on a named sequencer.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task OneWayBindWithSelectorOnSequencer()
{
AccountsViewModel accounts = await OpenAccountsAsync();
AccountsView view = new() { ViewModel = accounts };
VirtualClock uiThread = new();
using (view.OneWayBind(accounts, static x => x.TotalBalance, static v => v.TotalBalanceLabel.Text, FormatBalance, uiThread))
{
Console.WriteLine($"Waiting: '{view.TotalBalanceLabel.Text}'");
uiThread.AdvanceBy(NextTurn);
Console.WriteLine($"Written: '{view.TotalBalanceLabel.Text}'");
}
// Output:
// Waiting: ''
// Written: 'A$17,680.75'
}
/// <summary>Resolves the same converter-object binding while the app runs, with <c>BindOneWayUnsafe</c>. Use it when a path is not an inline lambda.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindOneWayUnsafeWithConverterObject()
{
AccountsViewModel accounts = await OpenAccountsAsync();
AccountsView view = new();
VirtualClock uiThread = new();
using (accounts.BindOneWayUnsafe(view, x => x.TotalBalance, v => v.TotalBalanceLabel.Text, new CurrencyTextConverter(), uiThread, GroupedFormat))
{
uiThread.AdvanceBy(NextTurn);
Console.WriteLine($"Written: '{view.TotalBalanceLabel.Text}'");
}
// Without a hint the converter falls back to two decimal places.
using (accounts.BindOneWayUnsafe(view, x => x.TotalBalance, v => v.TotalBalanceLabel.Text, new CurrencyTextConverter(), uiThread, null))
{
uiThread.AdvanceBy(NextTurn);
Console.WriteLine($"Written: '{view.TotalBalanceLabel.Text}'");
}
// Output:
// Written: '$17,681'
// Written: '$17,680.75'
}
/// <summary>Resolves the same view-first converter-object binding while the app runs, with <c>OneWayBindUnsafe</c>.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task OneWayBindUnsafeWithConverterObject()
{
AccountsViewModel accounts = await OpenAccountsAsync();
AccountsView view = new() { ViewModel = accounts };
VirtualClock uiThread = new();
using (view.OneWayBindUnsafe(accounts, x => x.TotalBalance, v => v.TotalBalanceLabel.Text, new CurrencyTextConverter(), uiThread, OneDecimalFormat))
{
uiThread.AdvanceBy(NextTurn);
Console.WriteLine($"Written: '{view.TotalBalanceLabel.Text}'");
}
// Output:
// Written: '$17,680.8'
}
/// <summary>
/// Passes a null scheduler to <c>BindOneWay</c>. Null means the same as naming no scheduler: the write happens on the
/// thread that owns the target, so a target with no owning thread is written inline. The argument is named because a
/// bare <c>null</c> also fits the string parameters of the overload that takes no scheduler.
/// </summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindOneWayWithNullScheduler()
{
IssueBoardViewModel board = await OpenIssueBoardAsync();
IssueBoardView view = new();
using (board.BindOneWay(view, static x => x.SelectedIssue!.Title, static v => v.IssueTitleLabel.Text, scheduler: null))
{
board.SelectedIssue = board.Issues[CheckoutIssueIndex];
Console.WriteLine(view.IssueTitleLabel.Text);
board.SelectedIssue = board.Issues[0];
Console.WriteLine(view.IssueTitleLabel.Text);
}
// Output:
// Checkout button unresponsive on Safari
// Add gift-card support
}
/// <summary>Converts with a function and passes a null scheduler; the label holds the text as soon as the binding is made.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task BindOneWayConvertedWithNullScheduler()
{
TodoListViewModel list = await OpenTodoListAsync();
TodoView view = new();
using (list.BindOneWay(view, static x => x.RemainingCount, static v => v.RemainingLabel.Text, static count => count.ToString(CultureInfo.InvariantCulture), scheduler: null))
{
Console.WriteLine(view.RemainingLabel.Text);
list.SelectedItem = list.Items[0];
await list.CompleteAsync();
Console.WriteLine(view.RemainingLabel.Text);
}
// Output:
// 3
// 2
}
/// <summary>Formats with a selector and passes a null scheduler to the view-first <c>OneWayBind</c>.</summary>
/// <returns>A task that completes when the example finishes.</returns>
public static async Task OneWayBindWithSelectorAndNullScheduler()
{
AccountsViewModel accounts = await OpenAccountsAsync();
AccountsView view = new() { ViewModel = accounts };
using (view.OneWayBind(accounts, static x => x.SelectedAccount!.Balance, static v => v.BalanceLabel.Text, FormatBalance, scheduler: null))
{
accounts.SelectedAccount = accounts.Accounts[0];
Console.WriteLine(view.BalanceLabel.Text);
accounts.SelectedAccount.Balance = DepositedBalance;
Console.WriteLine(view.BalanceLabel.Text);
}
// Output:
// A$2,450.75
// A$1,200.50
}
/// <summary>Formats an amount for a label.</summary>
/// <param name="amount">The amount of money.</param>
/// <returns>The amount with a currency sign and two decimal places.</returns>
private static string FormatBalance(decimal amount) => FormattableString.Invariant($"A${amount:N2}");
/// <summary>Signs in as Priya, opens the web shop repository and loads its open issues.</summary>
/// <returns>A task that completes with the board, which lists two open issues, newest first.</returns>
private static async Task<IssueBoardViewModel> OpenIssueBoardAsync()
{
IssueBoardViewModel board = new(InMemoryGitHubServer.CreateSeeded()) { Token = InMemoryGitHubServer.PriyaToken };
await board.SignInAsync();
board.SelectedRepository = board.Repositories[0];
await board.LoadIssuesAsync();
return board;
}
/// <summary>Loads the seeded to-do list.</summary>
/// <returns>A task that completes with the list, which holds three unfinished items and one finished item.</returns>
private static async Task<TodoListViewModel> OpenTodoListAsync()
{
TodoListViewModel list = new(InMemoryTodoStore.CreateSeeded());
await list.LoadAsync();
return list;
}
/// <summary>Loads the accounts of the seeded bank.</summary>
/// <returns>A task that completes with the accounts screen, which lists an everyday and a savings account and has nothing selected.</returns>
private static async Task<AccountsViewModel> OpenAccountsAsync()
{
AccountsViewModel accounts = new(new InMemoryBankingBackend());
await accounts.LoadAccountsAsync();
return accounts;
}
/// <summary>Lists the buckets of the storage service and picks the first.</summary>
/// <returns>A task that completes with the browser, which has a bucket selected.</returns>
private static async Task<StorageBrowserViewModel> OpenBucketAsync()
{
StorageBrowserViewModel browser = new(InMemoryObjectStorage.CreateSeeded());
await browser.LoadBucketsAsync();
browser.SelectedBucket = browser.Buckets[0];
return browser;
}
}