Entry在水平上下文中不采用LayoutOptions.StartAndExpand

时间:2014-06-08 01:17:44

标签: xamarin xamarin.forms

我想在水平Entry中使用展开 ButtonStackLayout

var item = new StackLayout { 
    Orientation = StackOrientation.Horizontal,
    HorizontalOptions = LayoutOptions.FillAndExpand,
    Children = {

        new Entry { 
            Placeholder = "Feldtitel",
            VerticalOptions = LayoutOptions.Center,
            HorizontalOptions = LayoutOptions.StartAndExpand // NOTE THIS
        },
        new Button{ 
            Text = CFieldDescription.getNameForFieldType( fieldType ),
            VerticalOptions = LayoutOptions.Center,
            HorizontalOptions = LayoutOptions.End
        }

    }};

虽然Entry位于开头,但Button已结束,Xamarin.Forms 并未更改Entry的大小以填充水平空间

enter image description here

我需要更改我的代码吗?或者我发现了一个错误?

1 个答案:

答案 0 :(得分:21)

Entry.HorizontalOptions更改为LayoutOptions.FillAndExpand以获得所需效果:

var item = new StackLayout { 
    Orientation = StackOrientation.Horizontal,
    HorizontalOptions = LayoutOptions.FillAndExpand,
    Spacing = 12, //you probably want this
    Children = {
        new Entry { 
            Placeholder = "Feldtitel",
            VerticalOptions = LayoutOptions.Center,
            HorizontalOptions = LayoutOptions.FillAndExpand //there, fixed
        },
        new Button{ 
            Text = CFieldDescription.getNameForFieldType( fieldType ),
            VerticalOptions = LayoutOptions.Center,
            HorizontalOptions = LayoutOptions.End
        }
    }};

看起来LayoutOptions需要一些好的文档。