Reputation: 9992
I have a stack panel and I have set its datacontext to my custom object "Questions" path in binding and I am adding framework elements at runtime and set the textblock's property to Binding(), it shows QuestionAnswer as object. I want to show the QuestionText. Is it becuase the class is abstract? I have a few classes which inherit from QuestionAnswer like TextBoxQuestionAnswer,CheckboxQuestionAnswer etc.
When I try using Binding("TextBoxQuestionAnswer.QuestionText") nothing displays on the screen
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; }
}
Upvotes: 0
Views: 58
Reputation: 93611
Bindings are to the names of properties, not to class names so Binding("TextBoxQuestionAnswer.QuestionText")
is not valid.
A stack panel is not much use for binding to a collection. You need a container that has an item template so you can get per item binding to a collection (listbox, grid etc).
We really need to see your Xaml and binding code to clarify this.
Upvotes: 1