I am trying to open an xaml-file (FlowDocument) in a WPF RichTextBox when the program starts by putting code in MainWindow(). I have tried several examples from the web, for example this one and several similiar ones, but the program does not even open. When I have put the exe-file and the xaml-file in a folder and click on the exe-file nothing happens. Here is all code in the cs-file:
using System.IO;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Markup;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
FileStream fs = new FileStream("test.xaml", FileMode.Open, FileAccess.Read);
FlowDocument content = XamlReader.Load(fs) as FlowDocument;
richTextBox1.Document = content;
}
}
}
And all code in the xaml-file:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<RichTextBox Name="richTextBox1" Width="300" Height="300" />
</Grid>
</Window>
Content of 'test.xaml' (in the same folder as the program):
<FlowDocument>
<Paragraph>I am an XAML-dokument.</Paragraph>
</FlowDocument>
What code will open an xaml-file in a WPF RichTextBox and interpret the FlowDocument markup when the program starts?
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph>I am an XAML-dokument.</Paragraph></FlowDocument>using (var fs = File.OpenRead("test.xaml")) { richTextBox1.Document = XamlReader.Load(fs) as FlowDocument; }xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">