Xamarin Forms XAML - Boolean attribute set from XAML

Emixam23Emixam23 ✭✭✭USMember ✭✭✭

Hi,

I don't understand something about how to set object attribute for xaml about boolean..

I have a MainPage.xaml like this where I set ProportionalSize to true:

<ContentPage.Resources>
  <ResourceDictionary>
    <converter:BooleanConverter x:Key="Boolean"/>
  </ResourceDictionary>
</ContentPage.Resources>

<ContentPage.Content>
  <!-- Background during loading of start -->
  <AbsoluteLayout>
    <local:CustomImage Source="{extension:ImageResource HomeBG.png}"
                     ProportionalWidth="100" ProportionalHeight="100" ProportionalSize="{True, Converter={StaticResource Boolean}}"
                     AbsoluteLayout.LayoutBounds="0.5, 0.5, 1, 1"
                     AbsoluteLayout.LayoutFlags="All"/>
  </AbsoluteLayout>
</ContentPage.Content>  

I use a customImage for some reason, this is the class

public class CustomImage : Image
{
    private bool _ProportionalSize;
    public bool ProportionalSize
    {
        get { return this._ProportionalSize; }
        set
        {
            this._ProportionalSize = value;
            TrySize();
        }
    }
}

Because neither true nor True works, I made a BooleanConverter

public class BooleanConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return (bool)value;
    }

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

However, it still doesn't work...


Additional information: Position 19:75. MarkupExtension not found for true
ProportionalSize="{True, Converter={StaticResource Boolean}}"


Does I'm doing something wrong?

Best Answer

Answers

  • ShawnCastrianni.5092ShawnCastrianni.5092 ✭✭✭ US ✭✭✭

    does just setting it to true not work?

    ProportionalSize="true"

  • Emixam23Emixam23 ✭✭✭ USMember ✭✭✭

    It throws an exception..

    String was not recognized as a valid Boolean.

  • Emixam23Emixam23 ✭✭✭ USMember ✭✭✭

    OMG I'm totaly stupid....

    ProportionalWidth="100" ProportionalHeight="100" are boolean value

    I have to set ImageSize="100, 100" ................................

    I'll close the question, so stpid I can be sometime ! :/

    Thank for help

Sign In or Register to comment.