Ido Wolf
Ido Wolf

Reputation: 181

Making a grid of objects

I'm trying to make something like a quiz application where 3 questions will be brought up on screen at a time, allowing the user the check a radio button containing "Yes" or "No", and have an answer come up appropriately to his response. The questions will continually come from a database I'm using.

After a few attempts I've figured that using x:Name property is not a great solution, since it doesn't allow me to use a loop in order to change the questions and answers. Is there any other way to make a grid with the same types of objects in each cell, being able to access each object inside each cell of the grid in the code-behind?

Upvotes: 0

Views: 91

Answers (1)

Palak Bhansali
Palak Bhansali

Reputation: 731

Here is list of steps you need to implement,

  • Need to create QuestionModel, contains question properties, make sure your model inherits INotifyPropertyChanged.
  • Need to create ViewModel, which contains data objects, public/dependency properties
  • Need to bind/set data objects/properties on viewmodel constructor
  • Need to set your ViewModel as a DataContext of your View(.xaml) (You can create this on zammel directly and codebehind as well
  • Need to bind your UI objects like Question/answers/yes-no with viewmodel properties accordingly

WPF/Silverlight has their own fundamentals like Data Binding, Resources, Compiler, Dependency Properties. Above steps comprises MVVM design pattern. During each steps, please google for specific stuff.

Upvotes: 1

Related Questions