【问题标题】:Powershell: TextBlock in Runspace – Add Inline with fontstylesPowershell:运行空间中的 TextBlock – 添加内联字体样式
【发布时间】:2017-12-07 13:30:44
【问题描述】:

我在使用 powershell 和设置 TextBlock 中文本的一部分时遇到问题。

我使用一个函数将文本推送到运行空间窗口和其中的 TextBlock,效果很好。

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

即使是颜色的变化也没有问题。但现在我想标记单个单词bold。我尝试了一种务实的方法:

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

不幸的是,这不起作用。你能帮我找到解决这个问题的方法吗?

【问题讨论】:

    标签: powershell textblock runspace


    【解决方案1】:

    你需要大写粗体:

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

    【讨论】:

    • 不幸的是,这没有帮助:/
    【解决方案2】:

    我找到了解决办法:

       $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"
        )
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      • 2013-01-23
      • 2017-05-26
      • 2018-08-15
      相关资源
      最近更新 更多