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:

// 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;


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:


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.