0

I am designing a folder explorer in WPF.

I am successful to browse a perticular drive [e:] using the below code :

<Window.Resources>
    <ObjectDataProvider x:Key="RootFolderDataProvider">
        <ObjectDataProvider.ObjectInstance>
            <folderExplorer:FolderExplorer FullPath="e:\" />
        </ObjectDataProvider.ObjectInstance>
    </ObjectDataProvider>

    <HierarchicalDataTemplate
        DataType    = "{x:Type folderExplorer:FolderExplorer}"
        ItemsSource = "{Binding Path=SubFolders}">
        <TextBlock Text="{Binding Path=Name}" />
    </HierarchicalDataTemplate>
</Window.Resources>


<TreeView Grid.Column="0"
          Name="RootTreeView"
          Background="AliceBlue"
          Foreground="Black" Grid.RowSpan="3" Margin="0,0,0,169">
    <TreeViewItem Header="Browse">
        <TreeViewItem.ItemsSource>
            <Binding Source="{StaticResource RootFolderDataProvider}">
                <Binding.Path>SubFolders</Binding.Path>
            </Binding>
        </TreeViewItem.ItemsSource>
    </TreeViewItem>
</TreeView>

How can I browse all drives, that is by Mycomputer. Let me know if any information is needed.

Akon
  • 272
  • 1
  • 6
  • 20
  • possible duplicate of [Folder browser to list all system drive in WPF](http://stackoverflow.com/questions/22375801/folder-browser-to-list-all-system-drive-in-wpf) – Akon Mar 24 '14 at 13:22

1 Answers1

1
public void LoadDirectories()
{
    var drives = DriveInfo.GetDrives();
    foreach (var drive in drives)
    {
        this.treeView.Items.Add(this.GetItem(drive));
    }

here is the link,

WPF treeview Directory

here is the sample to bind in XAML

File explorer WPF

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396