Skip to content

Commit 9701676

Browse files
committed
Revert back to working over c# core
1 parent 6541460 commit 9701676

File tree

4 files changed

+79
-5
lines changed

4 files changed

+79
-5
lines changed

refreshingBrowserViewModel.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
}

viewModels.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $Window.DataContext = [MainViewModel]::new()
3131
$Window.ShowDialog()
3232

3333

34-
class MainViewModel : ViewModelBase {
34+
class MainViewModel : WpfToolkit.ViewModelBase {
3535
[String] $Text = "*"
3636
[int] $Progress
3737
[Windows.Input.ICommand] $RunBackgroundTask
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Add-Type -AssemblyName PresentationFramework
22
$DebugPreference = 'continue'
3-
# . "$PSScriptRoot\wpf.ps1"
4-
. "$PSSCriptRoot\wpftoolkit.ps1"
3+
. "$PSScriptRoot\wpf.ps1"
54
. "$PSScriptRoot\viewModels.ps1"
65
$DebugPreference = 'continue'

wpf.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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+
34

45
[WpfToolkit.ViewModelBase]::InvokeCommand = $ExecutionContext.InvokeCommand
56
[WpfToolkit.ViewModelBase]::InitScript = {

0 commit comments

Comments
 (0)