Label Converter not working

Jassim Al Rahma 1,526 Reputation points

Hi, I have a Label that I want to show a value when returned from the database otherwise I want to show the word Add I tried Converter as below but not working.

    <local:MyProfileLabelConverter  x:Key="MyProfileLabelConverter" />

Here is my Label:

<Label x:Name="LabelMyHair" Text="{Binding Source={x:Reference .}, Path=Text, Converter={StaticResource MyProfileLabelConverter}}" VerticalOptions="Center" />

and this is my Converter:

public class MyProfileLabelConverter : IValueConverter
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        if (string.IsNullOrWhiteSpace((string)value)) return "Add";
        else return value;

        // return (string)value == "Add" ? IconFont.IconAdd : IconFont.IconEdit;
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        throw new NotImplementedException();// oneway binding, this method will not be called.

Thank you Jassim

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,995 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alessandro Caliaro 4,181 Reputation points