Xaml Stackpanel的遍历元素

Xaml Stackpanel的遍历元素,xaml,stackpanel,Xaml,Stackpanel,我是C#/XAML开发的新手,我刚刚开始创建非常基本的WindowsPhone8应用程序。我想使用stackpanel.Children.Add(_控件的名称)将stackpanel中添加的所有元素(控件)作为子元素添加到stackpanel。 现在我想在stackpanel中添加所有元素或控件,但不知道如何操作。我在网上搜索过,但找不到有用的链接 请帮助我了解如何实现它。您可以从StackPanel的子属性访问添加到StackPanel的所有控件,例如: foreach(var control

我是C#/XAML开发的新手,我刚刚开始创建非常基本的WindowsPhone8应用程序。我想使用stackpanel.Children.Add(_控件的名称)将stackpanel中添加的所有元素(控件)作为子元素添加到stackpanel。 现在我想在stackpanel中添加所有元素或控件,但不知道如何操作。我在网上搜索过,但找不到有用的链接


请帮助我了解如何实现它。

您可以从StackPanel的
子属性访问添加到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
}