lundi 29 juin 2015

get item from treeView c#

I have a TreeVe

<TreeView Name="files" Margin="0,0,569,108" Grid.Row="1" ItemsSource="{Binding s1}">
                        <TreeView.ItemTemplate>
                            <HierarchicalDataTemplate ItemsSource="{Binding Members}" >
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Name}" />
                                </StackPanel>
                                <HierarchicalDataTemplate.ItemTemplate>
                                    <DataTemplate>
                                        <CheckBox Name="CheckBox111" Checked="FileCheckBox_Checked" Unchecked="FileCheckBox_Unchecked">
                                            <ContentPresenter>
                                                <ContentPresenter.Content>
                                                    <StackPanel Orientation="Horizontal">
                                                        <Image Source="file.jpg" Margin="5,0,5,0" Width="20" Height="20" />
                                                        <TextBlock Text="{Binding Name}" />
                                                    </StackPanel>
                                                </ContentPresenter.Content>
                                            </ContentPresenter>
                                        </CheckBox>
                                    </DataTemplate>
                                </HierarchicalDataTemplate.ItemTemplate>
                            </HierarchicalDataTemplate>

                        </TreeView.ItemTemplate>
                    </TreeView>

and i want to check all the checkBoxs in the code-behind:

   private void AllFilesCheckBox_Checked(object sender, RoutedEventArgs e)
    {
        foreach (Object item in (files as ItemsControl).Items)
       {
           TreeViewItem t = files.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;

           foreach (Object item1 in t.Items)
           {
              // TreeViewItem t2 = item1 as TreeViewItem;
             //  CheckBox t1 =item1 as CheckBox;
           }
       }}

But I can not get access to the checkBox... I do not know how to get access to it.

thank you.

Aucun commentaire:

Enregistrer un commentaire