WPF which event to choose ?

Welcome Forums General PowerShell Q&A WPF which event to choose ?

This topic contains 2 replies, has 2 voices, and was last updated by

8 months, 3 weeks ago.

  • Author
  • #126231

    Topics: 1
    Replies: 1
    Points: -6
    Rank: Member

    Hi everyone,

    my goal is to start a process when the GUI is open and see the progress bar growing.

    The process work fine, but I only see the render at the end of the process and not during the process.

    I've tried to change the event (Activated/ContentRendered/Initialized/Loaded) but I still not have the correct result.

    Or maybe there is another way to do it ?

    add-type -AssemblyName PresentationFramework
    [xml]$FormoutFile = @"
    Title="MainWindow" Height="450" Width="800">
    $NR = (New-Object System.Xml.XmlNodeReader $FormoutFile)
    $Formout = [Windows.Markup.XamlReader]::load($NR)
    $ProgessBar = $Formout.findName("PB")
    $TextOut = $Formout.findName("TB_Text")
    $BT_Close = $Formout.findName("BT_Close")
    For ($i=0;$i-lt10;$i++){
    $TextOut.text+=@("Step $i`n")
  • #126248

    Topics: 2
    Replies: 31
    Points: 68
    Rank: Member

    The reason for seeing the progress at the end is because the script you are showing is single threaded. Essentially, it can't do the work and show the work at the same time.

    I've spent a lot of time doing multi-threaded windows at this point, but I got it started from this blog series, https://foxdeploy.com/2016/05/17/part-v-powershell-guis-responsive-apps-with-progress-bars/.

    Stephen Owen does a really good job of showing how this exact thing is done.

    Happy Coding!

  • #126305

    Topics: 1
    Replies: 1
    Points: -6
    Rank: Member

    Many thanks,

    I learn new stuff every days on Powershell, 5 days ago I don't know WPF, now I'm going to do multi thread.

    Going back to my code 😉

The topic ‘WPF which event to choose ?’ is closed to new replies.