WPF without XAML

J Trana picture J Trana · Apr 20, 2011 · Viewed 10.7k times · Source

Architecturally, I think WPF is pretty amazing. In general, I'm a big fan of the underlying rendering/animation inner workings. The flexibility of the templating and styling set up is pretty impressive.

But I loathe XAML - I feel like it complicates many things. I've used it on large and small applications and I've found myself many times trying to figure out how to do something in XAML for which the underlying principle is basic but the syntax is quirky. Not only that, but I've wondered many times how heavy certain parts of the parsing/binding are. (I know it's compiled, but I'm not sure how much is still evaluated at runtime)

XAML is just one way of building and loading the visual tree. Are there any frameworks for simplifying building the visual tree in a non-XML, code-based (but still largely declarative) way? Specifically, I'm interested in frameworks that mitigate any of the following issues while retaining an MVVM approach:

  1. Strongly typed binding. Specify that the ViewModel must conform to a specific type. I assume BaseBinding uses reflection under the hood and I'm a bit skeptical as to the speed of that, not to mention broken bindings being annoying.

  2. Faster binding, non-INotifyPropertyChanged binding. It seems like some sort of BindableProperty<T> could be created and the binding could listen directly to that rather than receiving all ViewModel property changes. And the use of a direct callback versus a string argument would also seem to be advantageous.

  3. A different approach to resource management; again, strongly typed dictionaries of some sort could be pretty nice. I'd almost like to see styles as lambdas or something to capture the strongly typed aspect.

In summary, any frameworks that are non-XAML based, fit well with MVVM, and are strongly typed?

Answer

Olmo picture Olmo · Jan 25, 2012

I support you in Xaml-free WPF. I love layout and binding capabilities of WPF but I hate XAML too. I would love that WPF could be written in plain C#, some advantages:

  • Object and Collection initializers could replace Xaml instantiations. (it's a pity that xaml prefers top-down than button up).
  • Binding converters could be just lambdas.
  • Styles could be just lambdas that modify an object after instantiation, no bloated <Setter> syntax.
  • DataTemplates would be just lambdas that create controls given an object
  • DataTemplateSelectors would be just a DataTemplate lambda that calls other DataTemplates.
  • ItemsControl Would be just a Foreach that takes a lambda (DataTemplate) and calls it again if a new item is added to the underlying collection.
  • x:Names would be just variable names.
  • No need for many MarkupExtensions
    • x:Static
    • x:Type (specially with complex generics too!)
  • UserControls would be just functions.

I think way too much complexity was added to WPF to allow it to be designed. Web development has already lost this battle from the old days of FrontPage to Razor.