An open API service indexing awesome lists of open source software.

https://github.com/saimel/Plugin.XamarinForms.Converters


https://github.com/saimel/Plugin.XamarinForms.Converters

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# Plugin.XamarinForms.Converters

Cross platform library containing a bunch of XAML converters for Xamarin Forms.

### Supported platforms

| Name | Tested |
| - | - |
| Android | Yes |
| iOS | Yes |

## Setup

Install this package into your PCL/.NetStandard project. It does not require additional configurations.

## Using the package

First, you just need to add the reference in your XAML file:

```XML
xmlns:conv="clr-namespace:Plugin.XamarinForms.Converters;assembly=Plugin.XamarinForms.Converters"

xmlns:enum="clr-namespace:Demo.Enums"
```

And then you can use it on this way:

```XML



None
Movie
Concert
Sports
CityTour

```
Enum declaration:

```C#
public enum EventType
{
None,
Movie,
Concert,
Sports,
[Description("City Tour")]
CityTour
}
```

#### There are more useful converters in this package you can use

* __General__
* EqualsConverter _(requires additional property)_
* InvertedBoolConverter
* IsNotNullConverter
* IsNullConverter
* EnumDescriptionConverter
* BoolToObjectConverter [[Read more]](#booltoobjectconverter) _(requires additional properties)_

* __Image__
* ByteArrayToImageConverter [[Read more]](#bytearraytoimageconverter)

* __Number__
* EmptyToNullNumberConverter [[Read more]](#emptyto_converter)
* EmptyToZeroConverter [[Read more]](#emptyto_converter) _(do not use for nullable properties)_
* IsPositiveConverter
* IsNegativeConverter
* IsNonPositiveConverter
* IsNonNegativeConverter
* IsLesserThanConverter _(requires additional property)_
* IsLesserOrEqualThanConverter _(requires additional property)_
* IsGreaterThanConverter _(requires additional property)_
* IsGreaterOrEqualThanConverter _(requires additional property)_
* IsInRangeConverter _(requires additional properties)_

* __String__
* SubstringConverter [[Read more]](#substringconverter) _(optional property)_
* ToLowerCaseConverter
* ToUpperCaseConverterer
* IsNonNullOrWhitespaceConverter A collaboration from [[ronymesquita]](https://github.com/ronymesquita)

## More examples

```XML


















```

## Detailed information

#### BoolToObjectConverter
This converter defines two properties `IfTrue` and `IfFalse` of type `object`. These properties represent the values you want to be returned depending on the boolean value of the bindable property you are using.

#### ByteArrayToImageConverter
For some reason I was required once to retreive byte array from images. After a couple of hours looking for a solution and trying out some approaches I found at __Stack Overflow__ I realized there wasn't an easy way to do it. So I decided to keep my `ItemsSource` as `byte[]` and then use a converter to bind it in my XAML. So that's it.

#### EmptyTo_Converter

When binding an entry to a numeric property, deleting entry's text on the UI doesn't update the target property.
__Ex:__ If the entry value is `123` and you start deleting, in some point the value will be `1` for both UI and view model. If you continue deleting the text on the UI will be an empty string however, binded property in view model stills `1`. By using these converters if you clear the entry, your binded property in view model will be `null` or `0`, depending of which converter is been used.

#### SubstringConverter

Truncates the input string to the length provided in `ConverterParameter` or to 50 characters if no value was provided. Also appends three dots if input's lenght is greater than provided length.

# Good luck!