Bonjour,

Pour des besoins pro je me mets à WPF via Blend et visual basic 2010 express.
Je dois faire un explorateur de fichiers et le lier pour afficher ultérieurement une image dans un grid.

En regardant un peu partout et adaptant à mes besoins j'ai un explorateur qui me renvoi que les dossiers (ou fichier selon ce que je lui passe) mais pas dossiers et fichiers.

Pour l'instant j'affiche en plus une listview pour vérifier mes fichiers mais à terme je veux que cette listview disparaisse pour avoir les fichiers avec le treeview contenant l'explorateur.

voici mon code xaml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:my="clr-namespace:Placement" 
	xmlns:local="clr-namespace:WPF_Explorer_Tree" 
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	x:Class="MainWindow"
	x:Name="Window"
	Title="MainWindow"
	Width="1300" Height="766" Background="Black" mc:Ignorable="d">
 <Window.Resources>
 
 
        <ObjectDataProvider x:Key="RootFolderDataProvider" >
            <ObjectDataProvider.ObjectInstance>
                <my:Folder FullPath="C:\"/>
            </ObjectDataProvider.ObjectInstance>
        </ObjectDataProvider>
 
 
<BitmapImage x:Key="Icon_FolderOpen"   UriSource="Resources/test.jpg"   />
<BitmapImage x:Key="Icon_FolderClosed" UriSource="Resources/Folder.gif" />
 
<Style x:Key="IconImageStyleSmall" TargetType="Image">
    <Setter Property="MaxWidth" Value="16"/>
    <Setter Property="MaxHeight" Value="16"/>
    <Setter Property="Margin" Value="1"/>
</Style>
 
		</Window.Resources>
 
 
	<Grid x:Name="LayoutRoot" Width="1300" Height="700" Background="#BF969696">
 
	        	<Grid Margin="1,0,0,0" Background="#FFA7A6A6"  Height="156.666" >
	        		<Grid.ColumnDefinitions>
	        			<ColumnDefinition Width="0.371*" />
	        			<ColumnDefinition Width="0.629*" />
                	</Grid.ColumnDefinitions>
	        	 <TreeView x:Name="treeView1" Grid.Column="0" Grid.Row="0" Margin="8,8,103.23,8" Background="#7F000000" Grid.ColumnSpan="1" Foreground="#FFE1FFAF" d:LayoutOverrides="HorizontalAlignment" BorderBrush="#FF4180F0">
            		   <TreeView.Resources>
        					<Style TargetType="{x:Type TreeViewItem}">
            					<Setter Property="HeaderTemplate">
               						 <Setter.Value>
                     					<HierarchicalDataTemplate 
		    								DataType    = "{x:Type my:Folder}"
            								ItemsSource = "{Binding Path=SubFolders}">
                       						<StackPanel Orientation="Horizontal">
                           						 <Image>
                   								 <Image.Style>
                        							<Style BasedOn="{StaticResource IconImageStyleSmall}" TargetType="Image">
                            							<Setter Property="Source" Value="{Binding Source={StaticResource Icon_FolderClosed}, Mode=OneTime}"/>
                            							<Style.Triggers>
                                						<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem}, Path=IsExpanded}" Value="True">
                                    					<Setter Property="Source" Value="{Binding Source={StaticResource Icon_FolderOpen}, Mode=OneTime}"/>
                                						</DataTrigger>
                            							</Style.Triggers>
                        							</Style>
                    							</Image.Style>
                								</Image>
                           						<TextBlock Text="{Binding Name}" />
                       						 </StackPanel>
                   						 </HierarchicalDataTemplate>
               						</Setter.Value>
            					</Setter>
        					</Style>
   						</TreeView.Resources>
						<TreeViewItem ItemsSource="{Binding SubFolders, Source={StaticResource RootFolderDataProvider}}" Header="Folders"  Foreground="#FF98E8DC" Background="Black"  />
        			</TreeView>
					<ListView Name="listView2" 
		ItemsSource="{Binding Path=SelectedItem.Files, ElementName=treeView1, Mode=OneWay}" Grid.Row="0" Grid.Column="1" Margin="0,8,0,19"  />
	        		</Grid>
 
	</Grid>
</Window>
Le code en VB.NET :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
 
 
Imports System
Imports System.IO
Imports System.Linq
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Text
 
Imports System.Windows.Threading
Imports System.Windows.Media.Animation
Imports System.Threading
Imports System.Windows.Resources
Imports System.Reflection
 
 
Class Window1
 
 
End Class
 
 
 
Public Class Folder
 
 
 
 
Private _folder As DirectoryInfo
    Private _subFolders As ObservableCollection(Of Folder)
    Private _files As ObservableCollection(Of FileInfo)
 
    Public Sub New()
        Me.FullPath = "c:\"
 
    End Sub 'New
 
 
    Public ReadOnly Property Name() As String
        Get
            Return Me._folder.Name
        End Get
    End Property
 
 
    Public Property FullPath() As String
        Get
            Return Me._folder.FullName
        End Get
 
        Set(value As String)
            If Directory.Exists(value) Then
                Me._folder = New DirectoryInfo(value)
            Else
                Throw New ArgumentException("must exist", "fullPath")
            End If
        End Set
    End Property
 
    ReadOnly Property Files() As ObservableCollection(Of FileInfo)
        Get
            If Me._files Is Nothing Then
                Me._files = New ObservableCollection(Of FileInfo)
 
                Dim fi As FileInfo() = Me._folder.GetFiles()
 
                Dim i As Integer
                For i = 0 To fi.Length - 1
                    Me._files.Add(fi(i))
                Next i
            End If
 
            Return Me._files
        End Get
    End Property
 
    ReadOnly Property SubFolders() As ObservableCollection(Of Folder)
 
        Get
            If Me._subFolders Is Nothing Then
                Try
 
                    Me._subFolders = New ObservableCollection(Of Folder)
 
                    Dim di As DirectoryInfo() = Me._folder.GetDirectories()
 
                    Dim i As Integer
                    For i = 0 To di.Length - 1
                        Dim newFolder As New Folder()
                        newFolder.FullPath = di(i).FullName
                        Me._subFolders.Add(newFolder)
                    Next i
                Catch ex As Exception
 
                    System.Diagnostics.Trace.WriteLine(ex.Message)
 
                End Try
            End If
 
            Return Me._subFolders
        End Get
    End Property
 
End Class
Merci de m'indiquer une piste ou une solution pour avoir un bon explorateur.