我是C#/ XAML开发的新手,我刚刚开始创建非常基本的Windows Phone 8应用程序。我想使用stackpanel.Children.Add(name_of_the_control)将添加到堆栈面板中的所有元素(控件)作为子元素添加到堆栈面板。现在,我想将所有元素或控件添加到堆栈面板中,但不知道该怎么做。我已经在网上搜索过,但没有获得有用的链接。
请帮助我实现它的过程。
您可以从其Children
属性访问添加到StackPanel的所有控件,例如:
foreach(var control in stackpanel.Children)
{
//here you can get each element of stackpanel in control variable
//further example :
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
}
//add other possible type of control you want to manipulate
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句