Prism and ListView, very very odd behavior...

JohnGynnJohnGynn USMember
edited September 2019 in Xamarin.Forms

Banging head against wall on this one. My ListView seems bound (on the EventToCommand, the item returned is the item selected in the list), but I cannot see the label that is in the list view. ANSWERS list (below) loads but I CANNOT see sAnswer, the bound text in the label in the list

<ListView x:Name="lstAnswers" RowHeight="120" 
              ItemsSource="{Binding Answers}"
              BackgroundColor="Silver">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Frame Padding="2" Margin="5" BackgroundColor="lightgrey">
                            <StackLayout Margin="5" Padding="5" BackgroundColor="Transparent">
                                <Label MaxLines="4" Text="{Binding sAnswer}" FontSize="15" TextColor="Black"/>
                            </StackLayout>
                        </Frame>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
            <ListView.Behaviors>
                <b:EventToCommandBehavior EventName="ItemTapped"
                                          Command="{Binding ItemTappedCommand}"
                                          EventArgsParameterPath="Item"/>

            </ListView.Behaviors>
        </ListView>

ViewModel:

private List<QuizAnswers> _answers;
public List<QuizAnswers> Answers
{
        get => _answers;
        set => SetProperty(ref _answers, value);
}

public override void OnNavigatedTo(INavigationParameters parameters)
    {
        LocalQuickQuiz = parameters.GetValue<QuickQuiz>("SelectedQuiz");
        LoadQuickQuiz(LocalQuickQuiz);
    }
private void LoadQuickQuiz(QuickQuiz SelectedQuiz)
    {
        Question = SelectedQuiz.Question;
        CorrectAnswer = SelectedQuiz.CorrectAnswer;

        try
        {
            Answers = SelectedQuiz.Answers;
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }

    }

public List<QuickQuiz> GetQuickQuizes(IEnumerable<ParseObject> results)
    {
        List<QuickQuiz> quiz = new List<QuickQuiz>();

        var quizlist = new QuickQuiz[results.Count()];

        var i = 0;
        foreach (var item in results)
        {
            QuickQuiz thisquiz = new QuickQuiz();
            List<QuizAnswers> tempquizanswer = new List<QuizAnswers>();
            thisquiz.Answers = tempquizanswer;

            QuizAnswers tempanswer1 = new QuizAnswers();
            QuizAnswers tempanswer2 = new QuizAnswers();
            QuizAnswers tempanswer3 = new QuizAnswers();
            QuizAnswers tempanswer4 = new QuizAnswers();

            thisquiz.objectId = item.ObjectId;
            thisquiz.createdAt = (System.DateTime)item.CreatedAt;
            thisquiz.updatedAt = (System.DateTime)item.UpdatedAt;
            thisquiz.Question = (String)item["Question"];
            thisquiz.CorrectAnswer = (String)item["CorrectAnswer"];

            tempanswer1.sAnswer = (String)item["A1"];
            tempanswer1.AnswerLetter = "A1";
            thisquiz.Answers.Add(tempanswer1);

            tempanswer2.sAnswer = (String)item["A2"];
            tempanswer2.AnswerLetter = "A2";
            thisquiz.Answers.Add(tempanswer2);

            tempanswer3.sAnswer = (String)item["A3"];
            tempanswer3.AnswerLetter = "A3";
            thisquiz.Answers.Add(tempanswer3);

            tempanswer4.sAnswer = (String)item["A4"];
            tempanswer4.AnswerLetter = "A4";
            thisquiz.Answers.Add(tempanswer4);

            quiz.Add(thisquiz);

            quizlist[i] = thisquiz;

            i++;
        }
        return quiz;
    }
}
public class QuizAnswers
{
    public string sAnswer;
    public string AnswerLetter;
}

ANY help is appreciated

Sign In or Register to comment.