File tree Expand file tree Collapse file tree 4 files changed +79
-5
lines changed Expand file tree Collapse file tree 4 files changed +79
-5
lines changed Original file line number Diff line number Diff line change
1
+
2
+ [string ]$xaml = @"
3
+ <Window
4
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5
+ Title="Initial Window" Width="800" Height="600">
6
+ <Grid>
7
+ <TextBox FontSize="24" Text="{Binding Text}" Grid.ColumnSpan="3" TextWrapping="Wrap" />
8
+ <ProgressBar Value="{Binding Progress}" Grid.ColumnSpan="3" Grid.Row="1" />
9
+
10
+ <Button Command="{Binding AddStar}" Content="Add *" Grid.Row="2" Grid.Column ="1" />
11
+ <Button Command="{Binding RunBackgroundTask}" Content="Run background task" Grid.Row="2" />
12
+
13
+ <Grid.RowDefinitions>
14
+ <RowDefinition/>
15
+ <RowDefinition/>
16
+ <RowDefinition/>
17
+ </Grid.RowDefinitions>
18
+
19
+ <Grid.ColumnDefinitions>
20
+ <ColumnDefinition/>
21
+ <ColumnDefinition/>
22
+ <ColumnDefinition/>
23
+ </Grid.ColumnDefinitions>
24
+ </Grid>
25
+ </Window>
26
+ "@
27
+
28
+
29
+ $Window = [Windows.Markup.XamlReader ]::Parse($xaml )
30
+ $Window.DataContext = [MainViewModel ]::new()
31
+ $Window.ShowDialog ()
32
+
33
+
34
+ class MainViewModel : WpfToolkit.ViewModelBase {
35
+ [String ] $Text = " *"
36
+ [int ] $Progress
37
+ [Windows.Input.ICommand ] $RunBackgroundTask
38
+ [Windows.Input.ICommand ] $AddStar
39
+
40
+
41
+ MainViewModel () {
42
+ Write-Host " Constructing Main view Model"
43
+
44
+ $this.Init (' Text' )
45
+ $this.Init (' Progress' )
46
+
47
+ $work = {
48
+ param ($this , $o )
49
+
50
+ Dispatch { $this.SetProgress (10 ) }
51
+ Start-Sleep - Seconds 2
52
+
53
+ Dispatch { $this.SetProgress (50 ) }
54
+
55
+ Start-Sleep - Seconds 2
56
+ Dispatch { $this.SetProgress (90 ) }
57
+ }
58
+
59
+ $callback = {
60
+ param ($this )
61
+
62
+ $this.SetText ($this.Text + " Background task done. " )
63
+ $this.SetProgress (100 )
64
+ }
65
+
66
+ $this.RunBackgroundTask = $this.NewBackgroundCommand ($work , $callback )
67
+
68
+ $this.AddStar = $this.NewCommand ({
69
+
70
+ Write-Host " is `$ this null?: $ ( $null -eq $this ) "
71
+ $this.SetText ($this.Text + " *" )
72
+ })
73
+ }
74
+ }
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ $Window.DataContext = [MainViewModel]::new()
31
31
$Window.ShowDialog ()
32
32
33
33
34
- class MainViewModel : ViewModelBase {
34
+ class MainViewModel : WpfToolkit. ViewModelBase {
35
35
[String ] $Text = " *"
36
36
[int ] $Progress
37
37
[Windows.Input.ICommand ] $RunBackgroundTask
Original file line number Diff line number Diff line change 1
1
Add-Type - AssemblyName PresentationFramework
2
2
$DebugPreference = ' continue'
3
- # . "$PSScriptRoot\wpf.ps1"
4
- . " $PSSCriptRoot \wpftoolkit.ps1"
3
+ . " $PSScriptRoot \wpf.ps1"
5
4
. " $PSScriptRoot \viewModels.ps1"
6
5
$DebugPreference = ' continue'
Original file line number Diff line number Diff line change 1
- Add-Type - Path " C:\projects\WPwshF\WpfInPowerShell\Toolkit\bin\Debug\Toolkit.dll"
2
- Add-Type - AssemblyName PresentationFramework
1
+ Add-Type - AssemblyName PresentationFramework
2
+ Add-Type - Path " $PSScriptRoot \WpfInPowerShell\Toolkit\bin\Debug\Toolkit.dll"
3
+
3
4
4
5
[WpfToolkit.ViewModelBase ]::InvokeCommand = $ExecutionContext.InvokeCommand
5
6
[WpfToolkit.ViewModelBase ]::InitScript = {
You can’t perform that action at this time.
0 commit comments