Xamarin Froms列表视图并非所有项目都显示

时间:2017-02-14 10:12:55

标签: c# xaml xamarin xamarin.forms portable-class-library

你好Xamarin受害者,

我的ListView存在问题,其中并未显示来自itemsource的所有项目。显示了总共12个项目中的6个。在这里你有我的XAML页面,你可以看到我如何使用listview(listview在中间部分使用):

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Prototype_Deinceps.views.subject.DetailPage"
         xmlns:multiplechoices="clr-namespace:Prototype_Deinceps.viewincludes.QuestionTypes;assembly=Prototype_Deinceps"
         xmlns:CustomElements="clr-namespace:Prototype_Deinceps.CustomElements;assembly=Prototype_Deinceps"
         Title="Detail">
<!-- ToolBar -->
<ContentPage.ToolbarItems>
<ToolbarItem Icon="Edit.png">
  <ToolbarItem.Text>
    <OnPlatform x:TypeArguments="x:String"
                iOS="Wijzig"/>
  </ToolbarItem.Text>
</ToolbarItem>
</ContentPage.ToolbarItems>

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="6*" />
    <RowDefinition Height= "9*" />
    <RowDefinition Height="6*" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>

  <!-- Top part of the screen that consist of basic info of the entity-->
  <StackLayout x:Name="BasicInfo" Margin="10,10,10,5" Grid.Row="0" Grid.Column="0">
    <Label Text="Basic Info" FontSize="Large"/>
    <BoxView Color="Black" WidthRequest ="100" HeightRequest="1"/>
    <Label x:Name="text1" />
    <Label x:Name="text2" />
    <Label x:Name="text3" />
    <Label x:Name="text4" />
  </StackLayout>
  <Image x:Name="EntityImage" Margin="10" Grid.Row="0" Grid.Column="1"/>
  <!-- End of Top -->

  <!-- Middle part of the screen where the questions are displayed about the entity-->
  <StackLayout x:Name="Questions" Margin="5,10,10,0" Grid.Row="1" Grid.ColumnSpan="2">
    <Label Text="Questions" FontSize="Large"/>
    <BoxView Color="Black" WidthRequest ="100" HeightRequest="1"/>
    <ScrollView>
      <ListView x:Name="QuestionListView"
                HasUnevenRows="True"
                ItemTapped="OnItemTapped">
        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell>
              <StackLayout x:Name="ListItem" Orientation="Horizontal" >
                <multiplechoices:MultipleChoice x:Name="multi" IsVisible="{Binding isMultipleChoice} "/>
                <multiplechoices:TrueFalse  IsVisible="{Binding isTrueFalse}"/>
                <multiplechoices:Text  IsVisible="{Binding isText}"/>
                <multiplechoices:LineText  IsVisible="{Binding isLineText}"/>                  
            </StackLayout>
            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>
    </ScrollView>
  </StackLayout>
  <!-- End of Middle -->

  <!-- Bottem part of the screen where you can put a note of the entity and save your info-->
  <StackLayout x:Name="Extra" Margin="0,10,30,5" Grid.Row="2" Grid.ColumnSpan="2">
    <Label Text="Opmerkingen" FontSize="Large"/>
    <BoxView Color="Black" WidthRequest ="100" HeightRequest="1"/>
    <CustomElements:CustomEditor PlaceHolder="Schrijf hier een opmerking..."/>
    <Button Text="Opslaan" HorizontalOptions="EndAndExpand" BackgroundColor="#AB001C" TextColor="White"/>
  </StackLayout>
  <!-- End of Bottom -->

</Grid>
</ContentPage>

这里有te部分,我可以定义我的物品。在一条令状中,我可以看到所有12个项目都被添加到了itemsource中。所以我怀疑问题是在这里,但为了它,这里是背后的代码:

 public partial class DetailPage : ContentPage
{

    public Subject sb;
    int i;
    public DetailPage(Subject subject)
    {
        InitializeComponent();

        sb = subject;
        TapGestureRecognizer tap = new TapGestureRecognizer();
        EntityImage.Source = ImageSource.FromFile("nobody_moriginal.jpg");
        text1.Text = subject.text1;
        text2.Text = subject.text2;
        text3.Text = subject.text3;
        text4.Text = subject.text4;

        tap.Tapped += OnTap;
        BasicInfo.GestureRecognizers.Add(tap);

        QuestionListView.ItemsSource = new List<Question>
        {
            new Question
            {
                Vraag = "1+1=?",
                TypeQuestion = Question.QuestionTypes.MulptipleChoice
            },
            new Question
            {
                Vraag= "Is dit waar?",
                TypeQuestion = Question.QuestionTypes.TrueFalse
            },
            new Question
            {
                Vraag= "Hoe ziet jou leven eruit?",
                TypeQuestion = Question.QuestionTypes.Text
            },
            new Question
            {
                Vraag= "Wat vind u van Tim?(Max 150 karakters)",
                TypeQuestion = Question.QuestionTypes.LineText
            },
            new Question
            {
                Vraag= "Wat vind u van Tim?(Max 150 karakters)",
                TypeQuestion = Question.QuestionTypes.LineText
            },
            new Question
            {
                Vraag= "Wat vind u van Tim?(Max 150 karakters)",
                TypeQuestion = Question.QuestionTypes.LineText
            },
            new Question
            {
                Vraag= "Wat vind u van Tim?(Max 150 karakters)",
                TypeQuestion = Question.QuestionTypes.LineText
            },
            new Question
            {
                Vraag= "Wat vind u van Tim?(Max 150 karakters)",
                TypeQuestion = Question.QuestionTypes.LineText
            },
            new Question
            {
                Vraag= "Wat vind u van Tim?(Max 150 karakters)",
                TypeQuestion = Question.QuestionTypes.LineText
            },
            new Question
            {
                Vraag= "Wat vind u van Tim?(Max 150 karakters)",
                TypeQuestion = Question.QuestionTypes.LineText
            },                new Question
            {
                Vraag= "Hoe ziet jou leven eruit?",
                TypeQuestion = Question.QuestionTypes.Text
            },                new Question
            {
                Vraag= "Hoe ziet jou leven eruit?",
                TypeQuestion = Question.QuestionTypes.Text
            }
        };
    }

    private async void OnTap(object sender, EventArgs e)
    {
        await Navigation.PushAsync(new BasicInfoPage(sb));
    }

    private void OnItemTapped(object sender, ItemTappedEventArgs e)
    {
        if (e == null) return; // has been set to null, do not 'process' tapped event
        ((ListView)sender).SelectedItem = null; // de-select the row
    }

提前谢谢!

2 个答案:

答案 0 :(得分:3)

默认情况下ListView拥有内部ScrollView,因此您无需在案例中使用ScrollView

答案 1 :(得分:0)

您在ScrollView中使用ListView。因此,您的所有项目都可能在ListView中,但您无法滚动到它们。