Enhancing security (and discovery) of the type seems marginal: one type of runtime that is less per resource.
There are other advantages here, even in the code you displayed. Using FsXaml is much more concise in your example and completely safe. Also, compilation will fail if serious problems arise in your XAML files when using the XAML Loader cancels this at run time.
Are there any other benefits?
There are many benefits -
- Shorter code
- Security type
- Named items displayed as properties in a safe type
- (Most important) Creates actual types that match your XAML types
The last point is the really “killer” advantage of FsXaml vs XamlReader - without this, it's almost impossible to do anything other than “toy” projects in WPF. You need to have “real types” appropriate for your types if you want to implement XAML.
For example, if you want to use UserControls that you design as data templates, you need UserControl to be the actual type, and not just some XAML as a resource. Using XamlReader, there is no way to reference this from another XAML. You also cannot reuse resources, extract data into your application or many other things (without having to manually write a huge amount of plumbing to do this at runtime).
In addition, with FsXaml 2+, you can subclass types and provide complete logic inside the “code behind”, similarly (albeit differently) to how you work in C #.
This brings Xaml much closer to the C # experience. There is still no BAML compilation (one of the disadvantages), but otherwise you get experience that works well with C # when working with F # with WPF.
source share