Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将rtf文件加载到Powershell中的WPF RichTextBox_Wpf_Powershell_Richtextbox - Fatal编程技术网

如何将rtf文件加载到Powershell中的WPF RichTextBox

如何将rtf文件加载到Powershell中的WPF RichTextBox,wpf,powershell,richtextbox,Wpf,Powershell,Richtextbox,有人知道我可以把rtf文件加载到wpf RichTextBox吗 在Windows.Forms中,我会这样做 RichTextFile.Loadfile(c:\myfile.rtf) 但我不知道如何在WPF中实现同样的效果 谢谢 Ben不确定PowerShell,但RichTextBox有一个文档属性,您可以使用该属性加载RTF文件。 以下是示例,以及一些帮助我的好网站: 以下是XAML: <StackPanel> <RichTextBox Height=

有人知道我可以把rtf文件加载到wpf RichTextBox吗

在Windows.Forms中,我会这样做

RichTextFile.Loadfile(c:\myfile.rtf) 
但我不知道如何在WPF中实现同样的效果

谢谢


Ben

不确定PowerShell,但RichTextBox有一个文档属性,您可以使用该属性加载RTF文件。
以下是示例,以及一些帮助我的好网站:

以下是XAML:

<StackPanel>
    <RichTextBox Height="200" x:Name="rtb"/>
    <Button Content="Load" Click="Button_Click" Width="50" />
</StackPanel>
public partial class MainView : Window
{
  public MainView()
  {
     InitializeComponent();
  }

  private void Button_Click(object sender, RoutedEventArgs e)
  {
     TextRange textRange;
     System.IO.FileStream fileStream;

     if (System.IO.File.Exists("Document.rtf"))
     {
        textRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
        using (fileStream = new System.IO.FileStream("Document.rtf", System.IO.FileMode.OpenOrCreate))
        {
           textRange.Load(fileStream, System.Windows.DataFormats.Rtf);
        }
     }
  }
}