0

I have a problem with powershell and styling a part of Text in a TextBlock.

I use a function to push text to a runspace window and a TextBlock in it, which works fine.

Function Update-Log {
    Param (
        $Content,
        $type = "Black"
    )
    $syncHash.Window.Dispatcher.invoke(
        [action]{$syncHash.log_txt.Foreground = $type; $syncHash.log_txt.Inlines.Add($Content); },
        "Normal"
    )
}

Even the change of color works without problems. But now I would like to mark individual words bold. I have tried a pragmatic approach:

Update-Log "Here is some <bold>bold</bold> text." 

Unfortunately this did not work. Can you help me to find a solution for this problem?

2 Answers2

1

I found a solution:

   $syncHash.TextBlockName.Dispatcher.invoke(
        [action]{ 
            $Run = New-Object System.Windows.Documents.Run
            $Run.Text = $Content
            $Run.FontWeight = $weight
            $Run.TextDecorations = $decorations
            $Run.FontStyle = $atyle
            $syncHash.TextBlockName.Inlines.Add($Run)
            },
        "Normal"
    )
}
0

You need to capitalize bold:

Update-Log "Here is some <Bold>bold</Bold> text." 
Palle Due
  • 5,929
  • 4
  • 17
  • 32