Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -AssemblyName PresentationFramework
- [xml]$Form = @"
- <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- Title="MainWindow" Height="150" Width="325">
- <Grid>
- <TextBlock Name="TextBlock" Text="0" HorizontalAlignment="Center"/>
- <Button Name="button_Do" Height="35" Width="120" Content="Do"/>
- </Grid>
- </Window>
- "@
- Function DoEvents()
- {
- $frame = New-Object System.Windows.Threading.DispatcherFrame
- [System.Windows.Threading.DispatcherOperationCallback]$CallBack = { $frame.Continue = $false }
- $CurrentDispatcher = [System.Windows.Threading.Dispatcher]::CurrentDispatcher
- $CurrentDispatcher.BeginInvoke("Background", $CallBack, $null)
- [System.Windows.Threading.Dispatcher]::PushFrame($frame)
- }
- $Reader = (New-Object System.Xml.XmlNodeReader $Form)
- $Window = [Windows.Markup.XamlReader]::Load($Reader)
- $TextBlock = $Window.FindName("TextBlock")
- $button_Do = $Window.FindName("button_Do")
- $button_Do.Add_Click({
- for ($i=1; $i -le 5; $i++)
- {
- $window.Title = $i
- $TextBlock.text = $i
- DoEvents
- #[System.Windows.Threading.Dispatcher]::CurrentDispatcher.Invoke("Background", [action]{ })
- #$Window.Dispatcher.Invoke("Background", [action]{})
- Start-sleep 1
- }
- })
- $Window.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement