0

I need to add a IsVisible property to entry cell using custom property

(I used height to change as visibility change but the code is broken) like:

public class BindableEntryCell : EntryCell
{
    public static readonly BindableProperty IsVisibleProperty = 
                    BindableProperty.Create(
                    propertyName: "IsVisible",
                    returnType: typeof(bool),
                    declaringType: typeof(BindableEntryCell),
                    propertyChanged: OnIsVisibleChanged);


    public bool IsVisible
    {
        get { return (bool)GetValue(IsVisibleProperty); }
        set { SetValue(IsVisibleProperty, value); }
    }


    private static void OnIsVisibleChanged(BindableObject bindable, object oldValue, object newValue)
    {
        if (bindable is BindableEntryCell EntryCell)
        {
            EntryCell.IsVisible = (bool)newValue;


            var YesHeight = EntryCell.Height;
            var NoHeight = 0;

            if ((bool)newValue)
                EntryCell.Height = YesHeight;
            else
                EntryCell.Height = NoHeight;
        }
    }
}

Or Using Value Converter (but there is a binding error mismatch binding even i bend to double) like:

public class HeightToVisabilityConverter : BaseConverter<HeightToVisabilityConverter>
{
    public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var Cell = (EntryCell)parameter;
        var height = Cell.Height;

        if ((bool)value ) 
            return 0;
        else
            return height;
    }

    public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

or any other way, I thought using height but any thing is accepted, please help?

Sherif Awad
  • 171
  • 2
  • 10
  • When you use the BindableProperty, what is the error? And how do you binding the converter? – Wendy Zang - MSFT Apr 13 '20 at 06:47
  • **BindableProperty **: It doesn't hit the property change method. **Value converter error**: "No property, bindable property, or event found for 'Height', or mismatching type between value and property", `Height="{Binding ChangPass, Converter={StaticResource HeightToVisabilityConverter}}"` – Sherif Awad Apr 14 '20 at 14:21
  • What is the ChangePass? Which property you used with converter? Height property? If yes, try the binding like below: `Height="{Binding ChangPass, Path=Height, Converter={StaticResource HeightToVisabilityConverter}}"` You could refer to the way below about how to binding converter: https://stackoverflow.com/questions/58987878/resizing-frame-and-controls-according-to-device-size-suggestions – Wendy Zang - MSFT Apr 21 '20 at 07:10

0 Answers0