I am trying to create a windows explorer.
I have succeeded in populating the treeView and listView like windows explorer, but i am having a problem opening the file on double click from the listView.
This is what i have so far:
try
{
//clears the collection so the listview has only the files of the folder thats clicked on
_fileDetails.Clear();
DirectoryInfo dirInfo = new DirectoryInfo( SelectedImagePath );
FileInfo[] info = dirInfo.GetFiles();
foreach (FileInfo fileInfo in info)
{
//adds files to the collection with its properties
_fileDetails.Add( new Details
{
FileName = fileInfo.Name,
Size = fileInfo.Length.ToString(),
DateCreated = fileInfo.CreationTime.ToString(),
DateModified = fileInfo.LastWriteTime.ToString(),
RevNumber = "?",
User = "?"
} );
}
}
where fileDetails is my ObservableCollection.
The mouse event:
protected void HandleDoubleClick( object sender, MouseButtonEventArgs e )
{
DependencyObject src = ( DependencyObject )( e.OriginalSource );
while (!( src is Control ))
src = VisualTreeHelper.GetParent( src );
MessageBox.Show( "*** Double clicked on a " + src.GetType().FullName +"********************" + sender.ToString() );
}
The binding:
<ListView Height="335" HorizontalAlignment="Right" Margin="0,12,12,0" Name="fileExplorerView" VerticalAlignment="Top" Width="509" Grid.Column="1" ItemsSource="{Binding ElementName=This, Path=fileDetails}">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<EventSetter Event="MouseDoubleClick" Handler="HandleDoubleClick"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="100" DisplayMemberBinding="{Binding FileName}"/>
<GridViewColumn Header="Size" Width="100" DisplayMemberBinding="{Binding Size}"/>
<GridViewColumn Header="Date Created" Width="100" DisplayMemberBinding="{Binding DateCreated}"/>
<GridViewColumn Header="Time Created" Width="100" DisplayMemberBinding="{Binding DateModified}"/>
<GridViewColumn Header="Revision Number" Width="100" DisplayMemberBinding="{Binding RevNumber}"/>
<GridViewColumn Header="Modified By" Width="100" DisplayMemberBinding="{Binding User}"/>
</GridView>
</ListView.View>
</ListView>
Instead of the messageBox in the mouse event, i will use a process to open the files.The problem is, i cant seem to figure out how to get the path of the selected file.
Thanks
All help will be appreciated.
Something like
(Why do you have a
Detailsclass anyway? I would just use theFileInfoobject)