【问题标题】:Xamarin.Forms Expand Entry field to fill ListView rowXamarin.Forms 展开条目字段以填充 ListView 行
【发布时间】:2019-01-18 11:19:51
【问题描述】:

我正在尝试获取一个 Entry 字段来填充 Xamarin.Forms 上的 ListView 行,但我尝试的所有操作都只是将 Entry 字段留下占位符的长度。

我已经在层次结构的几乎每个部分都尝试了使用“开始和展开”的 Horizo​​ntalOptions,它仍然保持占位符所需的最短长度。

如果我不将它放在 ListView 中,而是将它放在常规 StackLayout 中,那么它会毫无问题地填充。

以下 XAML 旨在在左侧显示一个图标,然后在右侧显示文本输入字段,填充到行尾。

我错过了什么?

 <ContentPage.Content>
            <ListView IsGroupingEnabled="True" GroupDisplayBinding="{Binding Title}" SeparatorVisibility="None" HasUnevenRows="True" Margin="10,5,10,0"  >
                <ListView.ItemTemplate>
                    <DataTemplate >
                    <ViewCell >
                        <StackLayout Orientation="Horizontal" Padding="5" HorizontalOptions="StartAndExpand">
                            <Image Source="{Binding ImageURL}" HeightRequest="30" WidthRequest="30"/>
                            <Entry Text="{Binding Input}" Placeholder="{Binding Name}" HorizontalOptions="StartAndExpand"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
</ContentPage.Content>

【问题讨论】:

    标签: listview xamarin.forms


    【解决方案1】:

    我没有测试,但是你可以尝试在ListView, StackLayout and Entry中设置HorizontalOptions=FillAndExpand

    <ContentPage.Content> <ListView IsGroupingEnabled="True" GroupDisplayBinding="{Binding Title}" SeparatorVisibility="None" HasUnevenRows="True" Margin="10,5,10,0" HorizontalOptions="FillAndExpand"> <ListView.ItemTemplate> <DataTemplate > <ViewCell > <StackLayout Orientation="Horizontal" Padding="5" HorizontalOptions="FillAndExpand"> <Image Source="{Binding ImageURL}" HeightRequest="30" WidthRequest="30"/> <Entry Text="{Binding Input}" Placeholder="{Binding Name}" HorizontalOptions="FillAndExpand"/> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </ContentPage.Content>

    【讨论】:

    • 很确定我已经尝试过了,我似乎已经尝试了所有组合,但是您的布局有效,所以谢谢。 :)
    猜你喜欢
    • 1970-01-01
    • 2017-01-15
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 2018-09-13
    • 2020-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多