Hacker News new | ask | show | jobs
by snuxoll 3232 days ago
JSON is no where near expressive enough to replace XAML, it would look a lot worse than what we have right now.

The XML-like syntax of XAML isn't the problem, it separates object properties from child content well due to it's nature - the bigger issue is how difficult binding syntax is to grok by anyone who hasn't been working with it for quite some time.

1 comments

> it separates object properties from child content well due to it's nature

This is only the case for trivial properties - there is also the expanded form of properties and that's where it muddies XAML very quickly.

For example, in a WPF project of mine I have a DataGrid with a Templated column parenting an ItemsControl with HyperLink children (it displays a list of Phone numbers for each Customer row).

This is my current XAML - I understand this is the minimum I need to achieve that effect: https://pastebin.com/cRjT2PG5

It could be simplified drastically in two ways, for example:

* Eliminate `<ItemsPanelTemplate>` and `<DataTemplate>` elements, they're implicit in 90% of cases and yet add another element and indent level without conveying significant information. They could be expressed as attributes of the `<ItemsControl.ItemsPanel>` and `<ItemsContorl.ItemTemplate>` property elements.

* Allow C# expressions and the composition of child-binding to be used in property bindings, not just `String.Format` strings. In my example I have to populate `<Hyperlink.Tooltip>` with a full `<TextBlock>` and `<MultiBinding>` element - why can't I just do `<HyperLink ToolTip="{Binding Kind} {Binding Number}">`? That alone would 10 lines of my 42 line example.

Another issue with XAML is that the creators of XAML failed to learn from HTML+CSS: while it succeeds at separating programming code from view-level concerns, it fails at separating presentation from content - it's like we're back in HTML3/4 days when <table> and <font> were all around and it was nearly impossible to tweak and standardise a UI. XAML does have <Style> and <Setter> elements but they're more used for setting Template properties - the end result is a horrid mess.

> * Eliminate `<ItemsPanelTemplate>` and `<DataTemplate>` elements, they're implicit in 90% of cases and yet add another element and indent level without conveying significant information. They could be expressed as attributes of the `<ItemsControl.ItemsPanel>` and `<ItemsContorl.ItemTemplate>` property elements.

XAML ultimately compiles to an object tree, if you're putting more than a reference, string, int, etc. into a property you need to construct it as a child element - if you want you are free to define the DataTemplate elsewhere in your XAML or in a resource dictionary and use the binding syntax.

> * Allow C# expressions and the composition of child-binding to be used in property bindings, not just `String.Format` strings. In my example I have to populate `<Hyperlink.Tooltip>` with a full `<TextBlock>` and `<MultiBinding>` element - why can't I just do `<HyperLink ToolTip="{Binding Kind} {Binding Number}">`? That alone would 10 lines of my 42 line example.

Use a converter? I know they're cumbersome to write, but that's what they exist for.

> Another issue with XAML is that the creators of XAML failed to learn from HTML+CSS: while it succeeds at separating programming code from view-level concerns, it fails at separating presentation from content - it's like we're back in HTML3/4 days when <table> and <font> were all around and it was nearly impossible to tweak and standardise a UI. XAML does have <Style> and <Setter> elements but they're more used for setting Template properties - the end result is a horrid mess.

Again, resource dictionaries, bind reusable styles to your elements. Syntax again sucks, `<TextBlock Style="{StaticResource AwesomeTextBlock}"/>`, and there IS the nagging issue that the styles are decided by the UI - but it's not too much worse than CSS classes.

Don't take any of this to mean your concerns aren't valid, but it's really not AS bad as you make it out to be. There's always room for improvement though!