nOmi
nOmi

Reputation: 295

Windows Phone Pivot

I am new to windows phone. I am trying to make pivot of questions . I want to add a text block and 2 radio buttons on each pivot item . I managed to add the textbook but didn't know how to add radio buttons.

var count = i + 1;
var textblok = new TextBlock { Text = o["questions"][i]["question"].ToString(), FontSize = 20,Width=450};
textblok.TextWrapping = TextWrapping.Wrap;
quizPivot.Items.Add(new PivotItem { Name="question"+count, Header = "Question " + count, Content = textblok,});

after adding container

   for (var i = 0; i < Globals.quizcount; i++) 
                {
                    var count = i + 1;
                    var stackpanel = new StackPanel();
                    var textblok = new TextBlock { Text = o["questions"][i]["question"].ToString(), FontSize = 20,Width=450};
                    textblok.TextWrapping = TextWrapping.Wrap;
                    stackpanel.Children.Add(textblok);
                    var radio = new RadioButton { Name = "useransYes", Content = "Yes" };
                    stackpanel.Children.Add(radio);
                    var radio1 = new RadioButton { Name = "useransNo", Content = "No" };
                    stackpanel.Children.Add(radio1);

                    //, HorizontalAlignment = "Left", Margin = "66,317,0,0", VerticalAlignment = "Top
                    quizPivot.Items.Add(new PivotItem { Name = "question" + count, Header = "Question " + count, Content = stackpanel });
                    quesId.Text = o["questions"][i]["_id"].ToString();
                }

2nd i want to know how to get all the pivot items i mean the contents in it.

Thanks

Upvotes: 0

Views: 134

Answers (1)

har07
har07

Reputation: 89285

You need to use a container control to add multiple UI controls to single PivotItem. For example using StackPanel as container :

//create the container
var stackpanel = new StackPanel();
//create textblock
var textblok = new TextBlock { Text = o["questions"][i]["question"].ToString(), FontSize = 20,Width=450};
textblok.TextWrapping = TextWrapping.Wrap;
//add to container
stackpanel.Children.Add(textblok);
//create radiobutton
var radiobutton = new RadioButton{Content = "Radio Button content"}
//add to container
stackpanel.Children.Add(radiobutton);
//add the container as content of pivot item
quizPivot.Items.Add(new PivotItem { Name="question"+count, Header = "Question " + count, Content = stackpanel,});

Anyway, there is another way around to accomplish this with much cleaner approach. Avoid creating UI controls from code by using data-binding and templating pivot item.

Upvotes: 1

Related Questions