Luca Thiede
Luca Thiede

Reputation: 3443

Xamarin: Data Binding Converter for FFImageLoading

I am new to Xamarin and try to use this library to display svg graphics in my forms app. In the documentation it says, to use the Data Binding

use a provided converter (eg. when using XAML):

Source="{Binding SvgFileName, Converter={StaticResource SvgImageSourceConverter}}"

In the the documentation to Data Binding basics it says, that converters are for example to convert a double between 0 and 1 to an int between 0 to 255 for using it as a color.

But I don't understand, what this converter does though. Why cant I just use

Source="{Binding SvgFileName}"

Upvotes: 1

Views: 279

Answers (1)

zimmerrol
zimmerrol

Reputation: 4951

Converters are a general aspect of xamarin and all silverlight/wpf alike technologies. They can be used to convert the the source of the binding into a different data format which then can be displayed in the view. You can find more information about them here, here and here.

I dont understand, what this converter does

It converts data from one type into a different type.

Why cant I just use ...

You can use this; you just have to make source, that the member SvgFileName of the data context has a suitable data format ( e.g. SvgImageSource). If you want to use a file name (as your variable name suggests) you can use a converter to convert the file name to the SvgImageSource object.

All in all, this is most of the times not recommended, as it is much better to bind a data type like an enum, bool, etc. to the view and to load the real image source via a converter.

Upvotes: 1

Related Questions