Élodie Petit
Élodie Petit

Reputation: 5914

Binding errors in Xamarin Forms

Is there a way I can see the binding errors in while developing Xamarin Forms apps? The Application Output tab shows nothing but the binding doesn't work. How can I debug bindings?

Upvotes: 0

Views: 1526

Answers (2)

GiampaoloGabba
GiampaoloGabba

Reputation: 1458

You can try to use the Compiled Bindings: https://learn.microsoft.com/xamarin/xamarin-forms/app-fundamentals/data-binding/compiled-bindings

You will have gain performance and precise error reporting

Upvotes: 1

Yehor Hromadskyi
Yehor Hromadskyi

Reputation: 3388

I'd like to suggest you to add EmptyConverter:

public class EmptyConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value;
    }
}

Then create instance of converter on your page:

<ContentPage.Resources>
    <ResourceDictionary>
      <converters:EmptyConverter x:Key="EmptyConverter"/>
    </ResourceDictionary>
</ContentPage.Resources>

Then add converter to label:

<Label Text="{Binding Text, Converter={StaticResource EmptyConverter}}"/>

Put breakpoints in Convert and ConvertBack methods and you'll be able to see all changes of binded values.

Hope this will help you.

Upvotes: 5

Related Questions