forked from dotnet/interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.dib
99 lines (66 loc) · 1.64 KB
/
README.dib
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
#!markdown
## Connect to the WPF app
First, let's start the WPF app and connect to it.
#!pwsh
Start-Process -NoNewWindow dotnet run
#!csharp
#!connect named-pipe --kernel-name wpf --pipe-name InteractiveWpf
#!markdown
## Formatter (Rendering)
#!csharp
#!wpf
#!dispatcher
using System.Windows.Media;
App.MainWindow.Background = new SolidColorBrush(Colors.Fuchsia);
App.MainWindow.Background
#!csharp
#!wpf
#!dispatcher
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows;
var grid = (Grid)App.MainWindow.Content;
grid.Background = new SolidColorBrush(Colors.CadetBlue);
grid
#!markdown
## View Model Stuff
Create and apply a new view model to the main window.
#!csharp
#!wpf
using System.ComponentModel;
public class TestViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _text = "Notebook Initial Value";
public string Text
{
get => _text;
set
{
if (_text != value)
{
_text = value;
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(nameof(Text)));
}
}
}
}
var vm = new TestViewModel();
#!dispatcher
App.MainWindow.DataContext = vm;
#!markdown
Update the value on the data bound property.
#!csharp
#!wpf
vm.Text = "Value changed!"
#!markdown
## Dispatcher stuff
Demonstate enabling and disabling running code on the dispatcher.
#!csharp
#!wpf
#!dispatcher --enabled true
//This should work
App.MainWindow.Title = "Done correctly";
#!dispatcher --enabled false
//This is expected to fail
App.MainWindow.Title = "Not so much";