C# WPF UI Tutorials: 02 – TreeViews and Value Converters


The second in a series of tutorials on creating WPF applications in C#

Dives into creating a TreeView copying some of the File Explorer functionality, as well as using Value Converters to convert paths to specific images in the tree

Source code here:



  1. I stumbled upon your videos when I was researching WPF .net core version.
    I tried the things I saw on the video and much to my surprise, I saw that the WPF .net core version is no where near ready to be used as production program. I converted my WPF .net core to WPF .net framework.

  2. Can't you use Path.GetFilename (https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getfilename) instead of writing the GetFileFolderName helper?

  3. Like this series so far 🙂
    I found another way to create the tree-view item and it's path and header.
    You could change:
    //Create a new item for it
    var item = new TreeViewItem();
    //Set header and path
    item.Header = drive;
    item.Tag = drive;

    var item = new TreeViewItem {Header = drive, Tag = drive};
    Both works for me 🙂

    Just two ways to do the same thing 🙂

  4. If you run your application and got ''WPF Application Has Stopped Working'', it's due to unhandled exceptions( the try-catch block cant handle this anymore ).Check out this solution : https://www.c-sharpcorner.com/blogs/how-to-handle-wpf-application-has-stopped-working

  5. I am trying to understand where i'm doing wrong because when i write…
    <Style TargetType="(x:Type TreeViewItem)">
    </Style> i get this error…
    the namespace prefix "(x" is not defined. i am new to WPF and C# in general and so i don't understand how to solve this. Thank you for great videos….they help alot.

  6. Using property bindings in XAML (instead of programatically changing properties in C#) must be related to proper MVVM practice, is that right? Is this done only to increase usability of the business logic among different UI setups?

    Thanks so much for the intensive training materials, most are too slow and generic to be worth the time.

  7. If a folder is being opened. How do i assign a new picture "folderopen" to that header? Since the Binding is only called when we create a TreeViewItem

  8. Hello AngelSix,
    Do you have any example how to implement TreeView w/ CheckBoxes that have the IsThreeState set to True in order to have a Toggeling of ON/OFF/MIXED? thanks in advance.

  9. At about 48:20 you say something that made the hair on the back of my neck stand up! You started talking about value converters and bindings and said something along the lines of – "This is just the simple stuff. We'll get into the more complicated things in later videos." At this point, however, my brain's already oversaturated and I know I will not even remember how to do a fraction of what you have already shown, and this is the "simple" stuff. I think I peed myself, a little bit.

    Also getting relative binds and going back up the tree to get the tag you mention that this is "messy" and "ugly" and here was the scary line again, you say – "and there are so many ways to get bindings…and you just get used to it.". Well, this is the overall problem learning to work within already super complication APIs. It is true there are many ways to do the same thing. But unfortunately, that means there are also many ways to try to get bindings that end up being a mish-mash of all the possible ways to do it right, that end up being WRONG!

    So you end up running down dead-end rabbit holes until finally, all you want to do is go watch dogs surfing on youtube!

  10. I love this video and your presentation style but for the love of god use Path.GetFilename(path) and Path.GetDirectoryName(path). THOSE are the cross platform way of getting the trailing text after the last slash or backslash.

  11. Encountered an error on:
    return new BitmapImage(new Uri($"pack://application,,,/{image}"))
    that says:
    'Invalid URI: The format of the URI could not be determined'
    (on pc win7 vs2017)

  12. @38:13 You could have just used Path.DirectorySeparatorChar from System.IO https://docs.microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar?view=netframework-4.8


Please enter your comment!
Please enter your name here