如何在Xamarin Forms中的Grid View中添加Entry Control?

时间:2017-09-12 04:59:32

标签: xaml listview xamarin gridview xamarin.forms

我在网格视图控件中添加Entry时遇到问题。我有一个列表视图,其中包含带复选框和条目的数据。如果用户选择某个项目,他还可以在条目中添加项目的数量。我正面临在网格视图中添加条目的问题。进入只显示一半。文本显示不正确。我在xaml中添加了条目为。

<StackLayout>
             <Label Text="Items"></Label>
             <ListView x:Name="ItemsListView" RowHeight="60">
                 <ListView.ItemTemplate>
                     <DataTemplate>
                         <ViewCell>
                             <ViewCell.View>
                                 <Grid Padding="5,0" RowSpacing="1" ColumnSpacing="1" >   
                                     <Grid.RowDefinitions>
                                         <RowDefinition Height="*"/>
                                     </Grid.RowDefinitions>

                                     <Grid.ColumnDefinitions>
                                         <ColumnDefinition Width="*" />
                                         <ColumnDefinition Width="*" />
                                         <ColumnDefinition Width="*" />
                                         <ColumnDefinition Width="*" />
                                     </Grid.ColumnDefinitions>

                                     <Label Text="{Binding Title}" Grid.ColumnSpan="2" Grid.Row="1" Margin="2" BackgroundColor="Green"></Label>

                                     <common:CheckBox Grid.Column="3" Grid.Row="1" HeightRequest="20" WidthRequest="20" 
                                                 VerticalOptions="Center" Checked="{Binding isChecked  ,Mode=TwoWay}" 
                                                 CheckedImage="checkbox_checked" UnCheckedImage="checkbox_unchecked" 
                                                 CommandParameter="{Binding .}"  BackgroundColor="Brown"/>
                                     <Entry Grid.Column="3" Grid.Row="1" IsEnabled="False" Text="CountStr" FontSize="Small"  VerticalOptions="End" BackgroundColor="Purple" />

                                 </Grid>
                             </ViewCell.View>
                         </ViewCell>
                     </DataTemplate>
                 </ListView.ItemTemplate>
             </ListView>
             <Button Text="Done" HorizontalOptions="CenterAndExpand"
                                                 CommandParameter="{Binding .}" Clicked="Button_Clicked"/>
 </StackLayout>

我得到了以下输出。

enter image description here

紫色背景控制是我的条目。文本显示不正确。任何帮助将不胜感激。提前致谢。 我已在Xamarin论坛here发布了问题。

2 个答案:

答案 0 :(得分:1)

像这样使用StackLayout

 <StackLayout Padding="5,0" Orientation="Horizontal">      
      <Label Text="{Binding Title}" WidthRequest="120" Margin="2" BackgroundColor="Green"/>
      <common:CheckBox HeightRequest="20" WidthRequest="20" Checked="{Binding isChecked, Mode=TwoWay}" CheckedImage="checkbox_checked" UnCheckedImage="checkbox_unchecked" CommandParameter="{Binding .}" BackgroundColor="Brown"/>
      <Entry WidthRequest="120" IsEnabled="False" Text="CountStr" FontSize="Small"  VerticalOptions="End" BackgroundColor="Purple" />
 </StackLayout>

您可以使用WidthRequest属性和Horizo​​ntalOption =&#34; FillAndExpand&#34;

更改大小

答案 1 :(得分:1)

enter image description here

<Grid Padding="5,0" RowSpacing="1" ColumnSpacing="1">
  <Grid.RowDefinitions>
    <RowDefinition Height="auto" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="auto" />
  </Grid.ColumnDefinitions>
  <Label Text="Apple" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="2" VerticalTextAlignment="Center" BackgroundColor="Green" />
  <Switch Grid.Row="0" Grid.Column="2" VerticalOptions="Center" HorizontalOptions="Center"  BackgroundColor="Brown" />
  <Entry Text="CountStr" Grid.Row="0" Grid.Column="3" IsEnabled="false" HorizontalOptions="Center" FontSize="Small" BackgroundColor="Purple"/>
</Grid>

注意:我在Switch与第三方复选框中进行了分析