Sam Hobbs

Sam Hobbs

  • 50
  • 28.9k
  • 2m

Split XAML into multiple files

Jun 1 2015 7:08 PM

Is it possible to split XAML into multiple files? I assume not since I cannot find anything describing how to.

Many compilers allow us to split code into multiple files such that the code exists in separate files but otherwise the code is the same in multiple files as if it were one large file. Can XAML be split up like that?

I know that I can split a WPF window up into multiple user controls, but that would require separate class libraries and separate code (".cs") files and could require splitting a class that should be one class into multiple classes.

For example, imagine a HTML editor. Editors often have a large toolbox yet the toolbox is mainly many commands to be applied to the document. Many of the commands would be exactly the same if they were items in a context menu. The context menu would exist as part of the document window yet the associated commands might be the same as for items in the toolbar.

So it would be best if the toolbar XAML were to not be a separate user control but instead it would be better to keep it in a file separate from the XAML for the rest of the window. I have searched for a way to do that and as best as I can tell XAML does not support what I am describing.


Answers (2)