https://github.com/Athari/Alba.Jaml
This library is NOT ready to be used in real projects. It's merely a proof-of-concept. If it gains substantial interest, I'll work on it more. Currently I need to make tough choices in architecture (see Open questions section below), and any input will be valuable.
- JSON syntax for WPF instead of built-in XML syntax.
- Short and concise syntax for built-in markup extensions: you'll never write
{Binding Path=Name, RelativeSource={RelativeSource AncestorType={x:Type Button}}, Converter={StaticResource Converter}}
again (it'll be{= ~Button.Name, Converter={@Converter} }
). - Inline C# expressions for bindings and multi-bindings, implemented as auto-generated converters: you'll never write
FirstValueEqualsToSecondOrThirdValueEqualsNullConverter
(it'll be{= ${=Property1} == ${=Property2} || ${=Property3} == null }
). Works with properties, style setters, triggers — anywhere where bindings can be used. - Simple syntax for "element" properties: you'll never write
<Setter.Value>
again. - Types are inferred automatically: you'll never repeat
ColumnDefinition
for each column again. - Simple setters and triggers syntax: you'll never painfully convert properties to setters again (they'll have the same syntax), you'll never write ten levels deep multi-triggers with multi-bindings again.
- (TODO) C#-style
using
directives.
_={
$: 'Window root',
Resources: [{
$: 'Style MyButtonStyle Button',
set: {
Background: 'Red', Foreground: 'Green'
},
on: {
'{=this.IsMouseOver}': {set: {
Background: 'Yellow', Foreground: 'Blue'
}}
}
}],
_: [{
$: 'Grid',
RowDefinitions: [ { Height: '*' } ],
ColumnDefinitions: [ { Width: '*' } ],
_: [{
$: 'Button btnPressMe', Content: 'Press me!', Style: '{@MyButtonStyle}'
}]
}]
}
JSON is a temporary choice. In future, the code above may look like this:
Window root {
Resources: [
Style MyButtonStyle Button {
set: {
Background: Red, Foreground: Green
},
on: {
{=this.IsMouseOver}: {set: {
Background: Yellow, Foreground: Blue
}}
}
}
],
Grid {
RowDefinitions: [ { Height: * } ],
ColumnDefinitions: [ { Width: * } ],
Button btnPressMe {
Content: 'Press me!', Style: {@MyButtonStyle}
}
}
}
or like this:
Window root
Resources:
Style MyButtonStyle Button
set:
Background: Red; Foreground: Green
on:
{=this.IsMouseOver}:
set:
Background: Yellow; Foreground: Blue
Grid
RowDefinitions: [ { Height: * } ]
ColumnDefinitions: [ { Width: * } ]
Button btnPressMe
Content: 'Press me!', Style: {@MyButtonStyle}
- Only built-in types from PresentationCore and PresentationFramework assemblies are supported.
- Error reporting is almost non-existent. If you write something wrong, you'll have to figure out what went wrong yourself (probably by commenting parts of the code).
- Numerous bugs. The library is written to prove it can be written, not to actually develop with it.
- Functionality
- Detailed error reporting
- What can be determined automatically, must be determined automatically
- Short and conscise syntax
- Readable and easy to remember syntax
- Effeciency and optimization
- Generated XAML readability
See wiki:
Example 2: TreeViewItem template
- Use just one type reflection mechanism (currently Reflection and XamlType-based). Also see Open questions below.
- Detailed error reporting with line and character numbers.
- Convert
on:[{ '{=this.Prop}': {...}
toTrigger
, notDataTrigger
withBinding RelativeSource=Self
. - More sensible XAML formatting (reach maximum line length, wrap only then?).
- Automatically detect types for Templates within styles etc.
- Detect types of multi-binding's sub-bindings in expressions, if possible.
- Evaluate posibility of a new language.
- Alternative 1: extend JSON. The best option is probably to modify Json.NET.
- Allow to specify type and name and possibly visibility of an object (either in front of
{
, like in QML, or after, like in markup extensions), to avoid$
property. - Allow to put any tokens into objects, not just properties, to avoid
_
property. - Allow any characters, except special characters, to be part of names and identifiers. Avoid unnecessary quotes.
- Make markup extensions first-class citizens in JAML. No more strings, make them true parsed objects.
- Allow to specify type and name and possibly visibility of an object (either in front of
- Alternative 2: use on existing script languages like Python, Lua etc.
- Alternative 1: extend JSON. The best option is probably to modify Json.NET.
- Solve the problem of referencing types in an assembly which contains JAML file. Also make
using
directive in JAML closer to C#'susing
.- Alternative 1: completely rely on public XAML parsing capabilities (using reflection) and make developers put JAML files into a separate project.
- Alternative 2: write alternative "reflectors" on source code. The best option is probably to use NRefactory.
- Alternative 3: use Microsoft Roslyn (currently CTP), whatever it is.
TL;DR: Simplified BSD License
Copyright (c) 2012, Alexander Prokhorov All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALEXANDER PROKHOROV BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The library uses the following third-party code:
- Json.NET by James Newton-King, JSON library for .NET.
- T4MultiFile by Brandon D'Imperio, T4 helper file to help generate multiple file outputs.
MS.Internal
namespace ofSystem.Xaml
from .NET Framework, partially extracted with .NET Reflector.