Skip to content

Instantly share code, notes, and snippets.

@jsonw23
Created February 27, 2012 20:42
Show Gist options
  • Save jsonw23/1926896 to your computer and use it in GitHub Desktop.
Save jsonw23/1926896 to your computer and use it in GitHub Desktop.
Folder Tree WPF Control: Part 1 - View
<UserControl x:Class="GeekJ.FolderTreeControl.FolderTree"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Loaded="FolderTree_Loaded">
<Grid>
<TreeView ItemsSource="{Binding Path=Drives}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Folders}">
<TextBlock Text="{Binding Path=Label}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
</UserControl>
namespace GeekJ.FolderTreeControl
{
public partial class FolderTree : UserControl
{
public FolderTree()
{
InitializeComponent();
}
private void FolderTree_Loaded(object sender, RoutedEventArgs e)
{
// default the datacontext if it hasn't been set or isn't the expected type
if (this.DataContext == null || !(this.DataContext is FolderTreeViewModel))
{
this.DataContext = new Model.FolderTreeViewModel();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment