Come caricare un file XAML a tempo di esecuzione ed inserirlo in una finestra
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="Page1">
<Grid>
<DockPanel HorizontalAlignment="Stretch">
<Button Name="button1" Content="Button" Height="100" Margin="10,10,10,10" />
</DockPanel>
</Grid>
</Page>
Per caricare lo XAML visuailizzato sopra:
//...
StreamReader mysr = new StreamReader("Page1.xaml");
DependencyObject rootObject = XamlReader.Load(mysr.BaseStream) as DependencyObject;
Content = rootObject;
//...