我正在VS2012中制作Windows 8应用程序,并尝试将对象(卡片)列表绑定到将显示两个字符串的用户控件。这里是我的用户控件的代码在一个页面上:绑定到用户控件“分配给属性失败”错误(Windows 8)
<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>
这是设置在后面的C#代码:
cardView.ItemsSource = Storage.content.Decks[currentDeck].Cards;
用户控制“TileControl”控制内部有这些变量:
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
}
}
错误列表中出现错误,说“无法分配给属性'Flashdeck.TileControl.AnswerText'”。它也适用于QuestionText。 该应用程序将编译并运行,但是当我打开包含用户控件的页面时会崩溃。我做错了什么给错误和崩溃?谢谢。
编辑:有关甲板和卡类的更多信息。甲板:
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;
}
}
卡:
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;
}
}
什么是“Value.question”,它在哪里定义? – Mayank