在Xamarin中,有没有一种方法可以通过编程的方式在它的一个子节点上设置Flex-Layout的Grow属性

p5fdfcr1  于 2023-05-04  发布在  其他
关注(0)|答案(1)|浏览(153)

我尝试以编程方式创建布局,但似乎无法弄清楚如何在其子元素上设置Flexlayout的Grow属性
为了澄清,我想以编程方式在Flexlayout的一个子元素上应用Grow,所以它占用了布局中的所有剩余空间
下面是我尝试用C#编写的Xaml代码示例

<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>

我想在运行时添加一些这种Flexlayout
我的代码到目前为止

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);
6mzjoqzu

6mzjoqzu1#

显然你需要像Grid和RowSpan那样使用它。
FlexLayout.SetGrow(editor, 1);

相关问题