我需要从在PowerShell中创建的RichTextBox
WPF中保存文件
我尝试通过System.Windows.Markup.XamlWriter
进行管道传输,我一直在想着删除掉的大量内容。我似乎无法得到这个。
if ($saveFile) {
$tr = new-object System.Windows.Documents.TextRange($RichEdit.Document.ContentStart,
$RichEdit.Document.ContentEnd)
$ascii = (new-Object System.Text.ASCIIEncoding).getbytes($tr)
# $docStream = new-Object System.IO.MemoryStream($ascii,$false)
$docStream = New-Object IO.FileStream $saveFile ,'Append','Write','Read'
$out = new-object System.Windows.Markup.XamlWriter.Save $tr, $docStream
}
答案 0 :(得分:0)
if ($saveFile) {
$RichEdit.SelectAll()
$as = New-Object IO.FileStream $saveFile ,'Create'
$a = $RichEdit.Selection.Save($as,[Windows.DataFormats]::Rtf)
}