Is there any way to load the screen layout dynamically during runtime?
I am looking to be able to load up screen layouts from configuration, without recompiling the entire app.
You can use XamlReader
to dynamically load XAML layouts at runtime. A simple example:
private void Add_Ellipse(object sender, RoutedEventArgs e)
{
var xaml = "<Ellipse Name=\"EllipseAdded\" Width=\"300.5\" Height=\"200\" Fill =\"Red\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"/>";
var ellipse = Windows.UI.Xaml.Markup.XamlReader.Load(xaml) as UIElement;
var host = (sender as FrameworkElement).Parent as Panel;
host.Children.Add(ellipse);
}
Note that you may notice page loading times increase if you load all your layouts this way, since the XAML needs to be parsed and you're also missing out on optimizations that are normally performed when the XAML is known at compile-time, but it gives you the flexibility you're asking for.