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