Search code examples
c#xamarindynamic

Is there a way to set Grow attribute of Flex-Layout on one of its children programmatically in Xamarin


I am trying to create layouts programmatically but can't seem to figure out how to set the Grow Attribute of a Flexlayout on one of its children

To Clarify I want to apply Grow on one of the Flexlayout's children programmatically, so It takes all left space in the layout

Here is an example of the Xaml code that I'm trying to do in C#

<StackLayout x:Name="ContainerLayout">
      <FlexLayout Direction="Row">
           <Editor Text="test"
                   FontSize="Large"
                   FlexLayout.Grow="1"/>

      <ImageButton Source="add_btn"
                   HeightRequest="40"
                   WidthRequest="40"
                   IsVisible="True"
                   Clicked="Translation_Clicked"/>
      <ImageButton Source="remove_btn"
                   HeightRequest="40"
                   WidthRequest="40"
                   IsVisible="False"
                   Clicked="Translation_Clicked"/>
       </FlexLayout>
</StackLayout>

I want to add a few of this Flexlayout during runtime

My code so far

FlexLayout flexLayout = new FlexLayout();
            flexLayout.Direction = FlexDirection.Row;

            Editor editor = new Editor();
            editor.FontSize = Device.GetNamedSize(NamedSize.Large,typeof(Editor));
    //Want to set Flexlayout.Grow to 1 here ,so the editor takes the left space

ContainerLayout.Children.Add(flexLayout);


Solution

  • You need to use it like Grid.RowSpan apparently.

    FlexLayout.SetGrow(editor, 1);