资 源 简 介
C# WPF 功能打印的示例,加载内容后,可在本程序中直接打印出XAML文档。
private void button2_Click(object sender, RoutedEventArgs e)
{//打印文件
PrintDialog MyDialog = new PrintDialog();
if ((MyDialog.ShowDialog() == true))
{
MyDialog.PrintVisual(this.richTextBox1 as Visual, "我的XAML打印文档");
}
}
private void button3_Click(object sender, RoutedEventArgs e)
{//保存文件
string MyFileName = "MyFile.XAML";
TextRange MyTextRange;
System.IO.FileStream MyStream;
MyTextRange = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);
MyStream = new System.IO.FileStream(MyFileName, System.IO.FileMode.Create);
MyTextRange.Save(MyStream, DataFormats.XamlPackage);
MyStream.Close();
}