Click here to Skip to main content
13,146,739 members (81,326 online)
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 16 Apr 2014

A WPF File ListView and ComboBox (Version II)

, 30 Jul 2014
Rate this:
Please Sign up or sign in to vote.
This is an alternative for "A WPF File ListView and ComboBox"

The project is now maintained here:


I was recently asked to add a 'File Tree Pane' into my editor ( and went looking for a good solution, because the component is really missing and it really bothers me too. The best solution I found, was written by Thomas Willwacher, as usual, here at CodeProject. I really like the concept that Thomas is using and reviewed the project in terms of integrating it in my editor, and while that is still too come, I found already some issues that would probably be difficult to fix in a project that is driven by an IoC (which I'd like to do next).

It is difficult to write this down correctly, so do not get me wrong here, I am really grateful that Thomas has posted his solution. Because I am not even sure whether I could have developed such a nice File Explorer concept to start with. But I saw architectural issues and I decided to get this done instead of putting it off. So, here is my take on this solution. I am posting it here in the hope that it is useful to others and that we might be able to develop this even further.


The solution presented here is about a File Explorer control that can be used in a Tool Window. The user should be able to browse directories, list their files, filter on the listed files, and open files via double click, drag & drop and context menu. The Drag & Drop and Context menu part is not presented here since I do not think this would be hard to add. The solution presented here is just about the same test application that Thomas had posted in his article. I only added a directory browser control and developed the architecture from scratch with MVVM in mind.

Using the code

The current articles discusses the code in in the download section. The in the download section is a refactored version that is currently under development based on my observations and Leung Yat Chun's suggestions in the forum's section. 

Re-using the code of the provided solution requires that you reference the Dll assemblies (FileListView and FolderBrowser), and copy & parts of the MainWindow.xaml code into your own view implementation. You will also need the code MainWindow.xaml.cs to create the necessary viewmodels. This is about all you need to re-use this solution in your own projects.

Points of Interest

The solution presented here contains 4 projects:

  • FileListView, FileListViewTest and
  • FolderBrowser, TestFolderBrowser.

The FileListView project is the assembly that contains the meat of the File Explorer controls that this article is focusing on. The FolderBrowser project originates from a different CodeProject article [2] and was included here since I felt that I did not need a Recent Files selection but a Recent Locations selection. So, re-factored this solution, as well, and included the result here.

The 'Test' projects in this solution contain a demo application that can be executed to check out how things work. The remainder of this article will focus on the FileListView project but feel free to ask questions/demand more information if you feel that I should document the FolderBrowser part in more detail.

The Views in the FileListView Project

The FileListView project is mainly partitioned in 3 views that are completely separated from each other.


The FilterComboBox inherits from the ComboBox control [3] and should be fully theme-able since I'd like to support bright and dark skins. This is basically the control where you enter such filter as: '*.png', '*.*', or (I extended this) '*.png|*.jpg|*.jpeg'. This filter is then applied to the list of files when the user selects the filter or presses the enter key in the text portion of the combobox.

<fview:FilterComboBox DataContext="{Binding FolderView.Filters}"

                      ItemsSource="{Binding CurrentItems}"

                      SelectedItem="{Binding SelectedItem, UpdateSourceTrigger=PropertyChanged}"

                      Text="{Binding CurrentFilter, UpdateSourceTrigger=PropertyChanged}"

                      fvbehav:SelectionChangedCommand.ChangedCommand="{Binding SelectionChanged}"






The above code shows how the FilterComboBox control is implemented in the MainWindow's Xaml. A noteworthy item is the SelectionChangedCommand behavior [4] which is basically a custom ComboBox behavior that binds itself to to the KeyUp and SelectionChanged event of the combobox. The behavior executes the bound SelectionChanged command in the FolderComboBoxViewModel when either event occurs. This in turn executes the SelectionChanged_Executed method which evaluates whether the currently entered path refers to a valid directory or not. The method raises the OnCurrentPathChanged event of the FolderChangedEventArgs type if the entered path was in fact in existence. This event is received by another viewmodel discussed further below.


The FolderComboBox control is the combobox that keeps the list of folders that a user can select as the base of his exploration. This includes the usual suspects, such as, Desktop, My Documents, and Drives but also contains a list of Recent Locations:

The FolderComboBox makes also use of the SelectionChanged behavior discussed above. It is very similar to the FilterComboBox except for 2 additions:

<Setter Property="ItemTemplate">
    <DataTemplate DataType="{x:Type vm:FSItemVM}">
      <Grid ToolTip="{Binding FullPath}" ToolTipService.IsEnabled="{Binding ShowToolTip}">
          <ColumnDefinition Width="{Binding Indentation}"/>
          <ColumnDefinition Width="20"/>
          <ColumnDefinition Width="100"/>
          <RowDefinition />
        <Image Grid.Row="0" Grid.Column="1" Source="{Binding Path=DisplayIcon}" Width="16" Height="16"/>
        <TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding DisplayName}" />

This ItemTemplate shows tha items display in the drop-down section of the ComboBox consist of an Image and a TextBlock. The ItemTemplate binds to instances of the ItemVM type which is part of the ObservableCollection<FSItemVM> CurrentItems collection in the FolderComboBoxViewModel.

<Setter Property="ItemContainerStyle">
    <Style TargetType="{x:Type ComboBoxItem}" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
        <DataTrigger Binding="{Binding}" Value="{x:Null}">
          <Setter Property="IsEnabled" Value="False" />
          <Setter Property="Template">
              <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                <Separator Width="0" Height="10"/>

The 2nd interesting thing in the FolderComboBox control is the ItemContainerStyle which includes a DataTrigger that inserts a Seperator when the bound value is null. The above Xaml literally converts a value of null into a seperator entry in the drop down list. This little trick inserts a Seperator in the drop-down list that allows us to group items such that users cannot click into the extra space (since seperators are not hit test visible).


The FListView is basically an out of the box ListView with an attached behavior addition that converts a double click into a bound DoubleClickCommand in the FileListViewViewModel [5].

The ViewModels in the FileListView Project

This solution includes a few more viewmodels than the original version 1. There is basically 1 viewmodel for each of the three controls documented in the previous section. The FolderComboBoxViewModel and the FileListViewModel make use of the FSItemVM class to manage their file specific collections. The FolderListViewModel is the heart of the solution since it instantiates the other control specific viewmodels and manages their events when they say, hey:

  • ...just selected a new Folder
    (OnCurrentPathChanged in FolderComboBoxViewModel and FileListViewModel)
  • ...just selected a new Filter (OnFilterChanged in FilterComboBoxViewModel)
  • ...just want to open a file (OnFileOpen in FileListViewModel)




Converting this project took me about 3-4 days of work but I think it was worth it since I have a much clearer understanding now and feel motivated to add other toys such as an async query and load of the FileListView. This could include a stop button shown in the Folder or Filter combobox to stop process that may take extra ordinary long when accessing slow devices.

Over all I have learned a few more tricks looking deep into someone else's code, so I am once again grateful for being part of this community. And now I am looking forward to see what the community thinks about this.


The Class diagrams in this article were drawn with #Develop (  I would like to say thank you for the original article and code version and the tips from Leung Yat Chun here at code project.


  • [1] A WPF File ListView and ComboBox (Version I) by Thomas Willwacher
  • [2] WPF Folder Browser by Erik Rude
  • [3] Inheriting from a Look Less WPF Control
  • [4] Patterns in Attached Behaviors
  • [5] AttachedCommandBehavior V2 aka ACB


  • 16.04.2014 Initial creation
  • 02.06.2014 Updated Version 2.1 to include metro design icons, a tree browser in the tool window area and much more (see Readme.txt files in zip archive) - next I'll either update the article or develop this even further :-) if I get the time to do either thing...


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Dirk Bahle
Germany Germany
The Windows Presentation Foundation (WPF) and C# are among my favorites since I started developing Edi:

and a few other projects on GitHub. I am normally an algorithms and structure type person but WPF has such interesting UI sides that I cannot help myself but get into this and MVVM.

You may also be interested in...

Comments and Discussions

SuggestionAuto Refresh Pin
Abdulrahman Bres17-Nov-16 3:20
professionalAbdulrahman Bres17-Nov-16 3:20 
GeneralRe: Auto Refresh Pin
Dirk Bahle28-Nov-16 7:01
memberDirk Bahle28-Nov-16 7:01 
GeneralRe: Auto Refresh Pin
Abdulrahman Bres28-Nov-16 13:41
professionalAbdulrahman Bres28-Nov-16 13:41 
QuestionInitial Path Pin
Abdulrahman Bres16-Nov-16 4:08
professionalAbdulrahman Bres16-Nov-16 4:08 
AnswerRe: Initial Path Pin
Dirk Bahle16-Nov-16 9:57
memberDirk Bahle16-Nov-16 9:57 
GeneralRe: Initial Path Pin
Abdulrahman Bres17-Nov-16 3:06
professionalAbdulrahman Bres17-Nov-16 3:06 
GeneralRe: Initial Path Pin
Dirk Bahle28-Nov-16 6:59
memberDirk Bahle28-Nov-16 6:59 
GeneralRe: Initial Path Pin
Abdulrahman Bres28-Nov-16 13:40
professionalAbdulrahman Bres28-Nov-16 13:40 
QuestionResolved - Using a library so Application.Current was null Pin
phill_mn24-Apr-15 8:16
memberphill_mn24-Apr-15 8:16 
AnswerRe: Resolved - Using a library so Application.Current was null Pin
Dirkster9925-Apr-15 23:49
memberDirkster9925-Apr-15 23:49 
QuestionApp Crash when loading Windows - related to Behaviors Pin
phill_mn24-Apr-15 4:05
memberphill_mn24-Apr-15 4:05 
AnswerRe: App Crash when loading Windows - related to Behaviors Pin
phill_mn24-Apr-15 4:58
memberphill_mn24-Apr-15 4:58 
GeneralRe: App Crash when loading Windows - related to Behaviors Pin
Dirkster9925-Apr-15 23:53
memberDirkster9925-Apr-15 23:53 
GeneralAnother version Pin
Leung Yat Chun8-May-14 7:10
memberLeung Yat Chun8-May-14 7:10 
GeneralRe: Another version Pin
Dirkster9911-May-14 7:03
memberDirkster9911-May-14 7:03 
GeneralRe: Another version Pin
Leung Yat Chun11-May-14 9:24
professionalLeung Yat Chun11-May-14 9:24 
GeneralRe: Another version Pin
Dirkster9912-May-14 11:49
memberDirkster9912-May-14 11:49 
GeneralRe: Another version Pin
Leung Yat Chun12-May-14 21:56
professionalLeung Yat Chun12-May-14 21:56 
GeneralRe: Another version Pin
Dirkster9913-May-14 12:05
memberDirkster9913-May-14 12:05 
QuestionVery interesting article about one alternative to a WPF File ListView & ComboBox Pin
Volynsky Alex16-Apr-14 23:08
professionalVolynsky Alex16-Apr-14 23:08 
AnswerRe: Very interesting article about one alternative to a WPF File ListView & ComboBox Pin
Dirkster9917-Apr-14 0:49
memberDirkster9917-Apr-14 0:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 30 Jul 2014
Article Copyright 2014 by Dirk Bahle
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid