How to bind AbsoluteLayout.LayoutBounds in XAML

I am trying to bind AbsoluteLayout.LayoutBounds in XAML, but i'm not sure exactly how to get it to work. Anyone know how to accomplish this?

Here is my code so far:

<AbsoluteLayout>
    <BoxView BackgroundColor="Red" HeightRequest="40" AbsoluteLayout.LayoutBounds="{Binding ProgessBounds}" AbsoluteLayout.LayoutFlags="PositionProportional,WidthProportional" />
</AbsoluteLayout>
public Rectangle ProgressBounds {
    get {
        return new Rectangle (0.5f, 0.5f, MyWidthVariable, AbsoluteLayout.AutoSize);
    }
}

Posts

  • JoshuaNovakJoshuaNovak USMember ✭✭

    Anyone? :(

  • JoshuaNovakJoshuaNovak USMember ✭✭

    Anybody?

  • YkshLeoYkshLeo USMember ✭✭✭✭

    @JoshuaNovak,

    Try this,

    AbsoluteLayout.LayoutBounds="{Binding ProgessBounds, Mode=OneWay}"

    Refer this forum post.

  • JoshuaNovakJoshuaNovak USMember ✭✭

    @Yksh.Leo That doesn't work. The issue is the ProgressBounds doesn't seem to register at all. I'm not sure if i'm supposed to return a rectangle, a string, or something else when I'm binding it in XAML. The forum talks about Binding a variable, but never says what that variable actually is.

  • threadythready CAMember ✭✭✭

    @JoshuaNovak - did you ever figure this one out? I'm also interested in getting this going. I'll let you know if I get it...

  • JoshuaNovakJoshuaNovak USMember ✭✭

    @MikeGagnon Yes I did. I was right the first time. Not sure why it didn't work before, but it started working eventually. I think what you have to keep an eye on is how your binding is setup.

  • threadythready CAMember ✭✭✭

    Great, thanks @JoshuaNovak

  • Emixam23Emixam23 USMember ✭✭✭

    I can't figure it out... I don't understand how can I set the layoutBounds from a bindable property defined in the C# side

  • FreefragFreefrag USMember ✭✭

    Which type was correct? Rectangle? or another?

  • tim.edelmanntim.edelmann DEMember

    The correct Type is a Rectangle to use with that binding for AbsoluteLayout. Like this:

    <Frame AbsoluteLayout.LayoutBounds="{Binding Path=TopBorder}" AbsoluteLayout.LayoutFlags="All"/>
    

    And in Backing cs file:

    public static readonly BindableProperty TopBorderProperty = BindableProperty.Create("TopBorder", typeof(Rectangle), typeof(ContentView), new Rectangle(0, 0, 1, 0.05));
    public Rectangle TopBorder
     {
       get { return (Rectangle)GetValue(TopBorderProperty); }
       set { SetValue(TopBorderProperty, value); }
    }
    
Sign In or Register to comment.