Live Chat Icon For mobile
Live Chat Icon

How do I load a Window from a XAML file dynamically?

Platform: WPF| Category: Window

You can load a xaml file dynamically as follows:

[C#]
// This file should then be next to the exe. If not specify a relative path.
FileStream xamlFile = new FileStream('ChartWindow.xaml', FileMode.Open, FileAccess.Read);

Window win = XamlReader.Load(xamlFile) as Window;

win.Show();

Note that any code-behind associated with the above xaml will not be loaded/processed.

In case, you have an assembly reference to a custom dll in the above xaml file, you should reference that assembly with a fully qualified namespace as follows:

[XAML]
xmlns:syncfusion='clr-namespace:Syncfusion.Windows.Chart;assembly=Syncfusion.Chart.WPF,Version=6.303.0.6,Culture=neutral,PublicKeyToken=3d67ed1f87d44c89'

The above assembly should then be present in the GAC for the runtime to find it.

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.