首页 > 解决方案 > Stacklayout 中的 Xamarin.Forms 输入字段在 iOS 中被截断,但在 Android 中不被截断

问题描述

我有一个包含许多 ViewCells 的 TableView。每个 ViewCell 都是 Label 和 Entry 字段的 StackLayout。在 Android 上,一切看起来都很好。在 iOS 上,任何具有字段的 ViewCell 都具有字段值截止值(即仅显示第一个字符,然后显示几个点)。选择器工作得很好顺便说一句。我已经尝试了不同的 MinimumWidthRequest 到一个高值、不同的 Horizo​​ntalOptions、OnAppearing() 中的 ForceLayout() 等。我怎样才能让这些字段扩展到必要的最小值,以显示完整的值?

安卓示例 iOS 示例

                <TableView>
                    <TableSection  x:Name="tblSingleCourse">
                        <ViewCell IsEnabled="True">
                            <StackLayout Orientation="Horizontal" HorizontalOptions="Center">
                                <Label Text="Course Name:" />
                                <Entry x:Name="txtCourseTitle" HorizontalOptions="Center"/>
                            </StackLayout>
                        </ViewCell>
                        <ViewCell IsEnabled="True">
                            <StackLayout Orientation="Horizontal" HorizontalOptions="Center">
                                <Label Text="Start Date:" />
                                <DatePicker x:Name="dpStartDate" Format="D"></DatePicker>
                            </StackLayout>
                        </ViewCell>
                    </TableSection>
                </TableView>

标签: xamarin.forms

解决方案


尝试这个

   <Grid Margin="10" RowSpacing="10">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" HorizontalOptions="FillAndExpand">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="7*"/>
            </Grid.ColumnDefinitions>
            <Label Text="Course Name:" FontAttributes="Bold" Grid.Column="0" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
            <Entry Grid.Column="1" PlaceholderColor="LightBlue" Placeholder="Enter Course name" x:Name="txtCourseTitle" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
        </Grid>

        <Grid Grid.Row="1" HorizontalOptions="FillAndExpand">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="7*"/>
            </Grid.ColumnDefinitions>
            <Label Text="Start Date:" FontAttributes="Bold" Grid.Column="0" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
            <Entry Grid.Column="1" PlaceholderColor="LightBlue" Placeholder="Enter StartDate" x:Name="dpStartDate" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
        </Grid>

        <Button CornerRadius="7" HorizontalOptions="FillAndExpand" Margin="20,0,20,0" Grid.Row="2" Text="Discard changes" FontSize="Small" TextColor="White" BackgroundColor="PaleVioletRed"></Button>
        <Button CornerRadius="7" HorizontalOptions="FillAndExpand" Margin="20,0,20,0" Grid.Row="3" Text="Save changes" FontSize="Small" TextColor="White" BackgroundColor="PaleVioletRed"></Button>

    </Grid>

推荐阅读