动态数据透视项内容值 [英] Dynamic Pivot item contents values
问题描述
我是pivot和wp8的新手.我想从动态数据透视项访问某些内容的值.这是我的动态数据透视项
I am new to pivot and wp8. i want to access some content's values from dynamic pivot items. here are my dynamic pivot items
for (var i = 0; i < Globals.quizcount; i++)
{
var count = i + 1;
if (count == Globals.quizcount)
{
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 { Content = "Yes", GroupName = "userans", Name = "ansYes" + count };
stackpanel.Children.Add(radio);
var radio1 = new RadioButton { Content = "No", GroupName = "userans", Name = "ansNo" + count };
stackpanel.Children.Add(radio1);
var button = new Button { Content = "Submit", Name = "submitQuiz" };
button.Click += new RoutedEventHandler(getAnswer);
stackpanel.Children.Add(button);
quizPivot.Items.Add(new PivotItem { Name = "question" + count, Header = "Question " + count, Content = stackpanel });
//quesId.Text = o["questions"][i]["_id"].ToString();Click="Button_Click"
}
else
{
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 { Content = "Yes", GroupName = "userans", Name = "useransYes" + count };
stackpanel.Children.Add(radio);
var radio1 = new RadioButton { Content = "No", GroupName = "userans", Name = "useransNo" + count };
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();
}
}
我不确定如何获取文本块的值并检查选中了哪个单选按钮.需要帮助
i am not sure how to get the values of the text block and check which radio button is checked. need help
谢谢
推荐答案
您可以尝试通过这种方式访问您动态创建的 TextBlock
和 RadioButton
:
You can try to access your dynamically created TextBlock
and RadioButton
this way :
//get stackpanel from the first pivot item
var pivotItem = (PivotItem)quizPivot.Items[0];
var stackpanel = (StackPanel)pivotItem.Content;
foreach(var control in stackpanel.Children)
{
if(control is RadioButton)
{
var radio = (RadioButton)control;
//do something with RadioButton
}
else if(control is TextBlock)
{
var textblok = (TextBlock)control;
//do something with TextBlock
}
}
上面的示例演示了如何从第一个数据透视项 (quizPivot.Items[0]
) 获取控件.这与您从 C# 代码创建这些控件时所做的逻辑基本相反.
Example above demonstrates on how to get controls from the first pivot item (quizPivot.Items[0]
). That is basically reversed logic from what you did when creating those controls from C# code.
这篇关于动态数据透视项内容值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!