Silverlight绑定问题

时间:2011-07-07 09:44:31

标签: silverlight binding

我有一个堆栈面板,我已将其datacontext设置为绑定中的自定义对象“Questions”路径,我在运行时添加框架元素并将textblock的属性设置为Binding(),它将QuestionAnswer显示为对象。我想显示QuestionText。这是因为班级是抽象的吗? 我有一些继承自QuestionAnswer的课程,如TextBoxQuestionAnswer,CheckboxQuestionAnswer等。

当我尝试使用Binding(“TextBoxQuestionAnswer.QuestionText”)时,屏幕上不显示任何内容

public class Page
{
        public int PageID { get; set; }
        public ObservableCollection<QuestionAnswer> Questions { get; set; }
}

public abstract class QuestionAnswer
    {
        public int QuestionID { get; set; }
        public string QuestionText { get; set; }
        public QuestionType QuestionType { get; set; }
        public Dictionary<string, string> AnswerOptions { get; set; }
        public string AnswerText { get; set; }
        public AnswerResponse AnswerResponse { get; set; }
    }

1 个答案:

答案 0 :(得分:1)

绑定是属性的名称,而不是类名,因此Binding("TextBoxQuestionAnswer.QuestionText")无效。

堆栈面板用于绑定到集合的用处不大。您需要一个具有项目模板的容器,以便您可以将每个项目绑定到一个集合(列表框,网格等)。

我们确实需要查看您的Xaml和绑定代码以澄清这一点。