【问题标题】:Traversing elements of StackpanelStackpanel 的遍历元素
【发布时间】:2014-03-10 19:29:11
【问题描述】:

我是 C#/XAML 开发的新手,我刚刚开始创建非常基本的 windows phone 8 应用程序。我想使用stackpanel.Children.Add(name_of_the_control)将stackpanel中添加的所有元素(控件)作为子项添加到stackpanel。 现在我想获取堆栈面板中添加的所有元素或控件,但不知道该怎么做。我在网上搜索过,但找不到有用的链接。

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

【问题讨论】:

    标签: xaml stackpanel


    【解决方案1】:

    您可以从 StackPanel 的 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-16
      相关资源
      最近更新 更多