/
ObservableObjectPage.xaml
100 lines (89 loc) · 4.38 KB
/
ObservableObjectPage.xaml
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
<Page
x:Class="MvvmSampleUwp.Views.ObservableObjectPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:MvvmSampleUwp.Controls"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
NavigationCacheMode="Enabled"
mc:Ignorable="d">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Loaded">
<core:InvokeCommandAction Command="{x:Bind ViewModel.LoadDocsCommand}" CommandParameter="ObservableObject" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
<ScrollViewer Padding="{StaticResource DocumentationPageContentPadding}" CanContentRenderOutsideBounds="True">
<StackPanel Spacing="16">
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('ObservableObject'), Mode=OneWay}" />
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('How it works'), Mode=OneWay}" />
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('Simple property'), Mode=OneWay}" />
<controls:InteractiveSample xml:space="preserve">
<controls:InteractiveSample.Content>
<StackPanel Spacing="8">
<!-- Simple property sample -->
<TextBox PlaceholderText="Type here to update the text below" Text="{x:Bind ViewModel.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Text="{x:Bind ViewModel.Name, Mode=OneWay}" />
</StackPanel>
</controls:InteractiveSample.Content>
<controls:InteractiveSample.XamlCode>
<StackPanel Spacing="8">
<TextBox
PlaceholderText="Type here to update the text below"
Text="{x:Bind ViewModel.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="{x:Bind ViewModel.Name, Mode=OneWay}"/>
</StackPanel>
</controls:InteractiveSample.XamlCode>
<controls:InteractiveSample.CSharpCode>
private string name;
/// <summary>
/// Gets or sets the name to display.
/// </summary>
public string Name
{
get => name;
set => SetProperty(ref name, value);
}
</controls:InteractiveSample.CSharpCode>
</controls:InteractiveSample>
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('Wrapping a non-observable model'), Mode=OneWay}" />
<controls:DocumentationBlock Text="{x:Bind ViewModel.GetParagraph('Handling `Task<T>` properties'), Mode=OneWay}" />
<controls:InteractiveSample xml:space="preserve">
<controls:InteractiveSample.Content>
<StackPanel Spacing="8">
<!-- Async property sample -->
<Button Click="{x:Bind ViewModel.ReloadTask}" Content="Click me to load a Task to await" />
<TextBlock Text="{x:Bind ViewModel.MyTask.Status, Mode=OneWay}" />
</StackPanel>
</controls:InteractiveSample.Content>
<controls:InteractiveSample.XamlCode>
<StackPanel Spacing="8">
<Button
Content="Click me to load a Task to await"
Click="{x:Bind ViewModel.ReloadTask}"/>
<TextBlock Text="{x:Bind ViewModel.MyTask.Status, Mode=OneWay}"/>
</StackPanel>
</controls:InteractiveSample.XamlCode>
<controls:InteractiveSample.CSharpCode>
private TaskNotifier myTask;
/// <summary>
/// Gets or sets the name to display.
/// </summary>
public Task MyTask
{
get => myTask;
private set => SetPropertyAndNotifyOnCompletion(ref myTask, value);
}
/// <summary>
/// Simulates an asynchronous method.
/// </summary>
public void ReloadTask()
{
MyTask = Task.Delay(3000);
}
</controls:InteractiveSample.CSharpCode>
</controls:InteractiveSample>
</StackPanel>
</ScrollViewer>
</Page>