I am making a Windows 8 app in VS2012 and trying to bind a list of objects (cards) to a user control that will display two strings. Here is my code for the user control on one page:
<FlipView x:Name="cardView"/>
<FlipView.ItemTemplate>
<DataTemplate>
<local:TileControl x:Name="cardTile" Width="600" Height="400" QuestionText="{Binding Value.question}" AnswerText="{Binding Value.answer}"/>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
This is set in the C# code behind:
cardView.ItemsSource = Storage.content.Decks[currentDeck].Cards;
The user control 'TileControl' control has these variables inside:
public string questionTextStr { get; set; }
public string answerTextStr { get; set; }
public string QuestionText
{
get
{
return questionTextStr;
}
set
{
questionTextStr = value;
questionText.Text = value; //set the textbox content
}
}
public string AnswerText
{
get
{
return answerTextStr;
}
set
{
answerTextStr = value;
answerText.Text = value; //set the textbox content
}
}
There is an error in the Error List saying "Failed to assign to property 'Flashdeck.TileControl.AnswerText' ". And it applies to the QuestionText too. The app will compile and run but when then crash when I open the page with the user control in it. What am I doing wrong to give an error and crash? Thanks.
Edit: More info on the decks and cards class. Deck:
public class Deck
{
public List<Card> Cards { get; set; }
public bool flagged { get; set; }
public Deck()
{
}
public Deck(List<Card> iCards)
{
Cards = iCards;
flagged = false;
}
public Deck(List<Card> iCards, bool iFlag)
{
Cards = iCards;
flagged = iFlag;
}
}
Card:
public class Card
{
public string question { get; set; }
public string answer { get; set; }
public bool flagged { get; set; }
public Card()
{
}
public Card(string iQ, string iA)
{
question = iQ;
answer = iA;
flagged = false;
}
}