XAML platforms use binding converters to transform data bound to properties. Most of us wrote, or at least saw code like this:
<TextBlock Visibility="{Binding ShouldBeVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
(don’t forget, you also need to add BooleanToVisibilityConverter object to resources collection)
This is because property of type bool
cannot be implicitly converted to Visibility
. So, you can either use a converter already provided by a framework or write you own. Converter would take boolean value as an argument and return visibility. It means, that every time your data cannot be directly applied to a markup you need to write a class that would deal with it.
Ammy strives to make all previously tedious tasks feel easy and natural. So, we have added inline binding converters.
Example from above would read like this:
bind ShouldBeVisible convert (bool visible) => visible ? Visibility.Visible : Visibility.Hidden
In short, it takes a bound value and applies a lambda expression provided by you. You can do pretty cool stuff with it, like toggling visibility depending on width:
Visibility: bind ActualWidth from $this convert (double width) => width > 600 ? Visibility.Visible : Visibility.Hidden
or formatting complex strings:
Text: bind //Empty Path means 'bind to datacontext' convert (Guest guest) => guest.FirstName[0] + ". " + guest.LastName
or changing background color depending on a gender:
Background: bind Gender convert (Gender gender) => gender == Gender.Male ? Brushes.LightBlue : Brushes.Pink
Binding expressions support most of the stuff C# compilers supports. But it’s a very simplified syntax, so you can’t use statements, define variables or write any code that is beyond converter scope.
Here is a video of binding converters being used in practice.
To use Ammy you need Ammy Visual Studio Extension and Ammy NuGet package.
For more information, please refer to www.ammyui.com/documentation/quickstart
Project website: www.ammyui.com