迭代控件以检索其子项

时间:2012-06-21 19:34:24

标签: c# wpf xaml

我在工具箱中添加工具箱项目,它被嵌入到xaml上的扩展器控件中。如何在这些工具箱项之间进行迭代和遍历?我的假设是工具箱是工具箱的子项,还是应该通过扩展器?

感谢。

XAML来到这里:

    <StackPanel Grid.Column="0" Margin="0,0,5,0">                    
            <Label Name="lblFind">Find:</Label>
        <StackPanel Name="spFind" Orientation="Horizontal">
        <TextBox Name="txtFind" Width="200" Height="22" ></TextBox>

        <Button Content="Go" Width="60" Height="30"
                IsEnabled="{Binding ElementName=txtFind, Path=Text.Length, Mode=OneWay}" Click="Button_Click" />
        </StackPanel>
        **<Expander x:Name="expander_Controls" Header="Controls" Content="{StaticResource myRESOURCE}" IsExpanded="True" />**


    </StackPanel>
        </ScrollViewer>
    <!-- GridSplitter -->
    <GridSplitter Focusable="False" Width="2" Background="LightGray"
            VerticalAlignment="Stretch" HorizontalAlignment="Right"/>


    <StackPanel Grid.Column="5" Background="AliceBlue">
        <ListView Background="LightGray" Opacity="1" ForceCursor="False" x:Name="myTree" x:FieldModifier="public">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Nodes" Width="80"/>
                 </GridView>
            </ListView.View>
        </ListView>
    </StackPanel>

溶液:

var myList = this.FindResource("MyResource") as Toolbox;

for (int i = 0; i <= (myList .Items.Count - 1); i++)
{
    Object objResult = myList.GetType().GetProperty("Tag").GetValue(myList.Items[i], null);
    MessageBox.Show(objList.ToString());
    }

0 个答案:

没有答案