Created
February 27, 2012 20:42
-
-
Save jsonw23/1926896 to your computer and use it in GitHub Desktop.
Folder Tree WPF Control: Part 1 - View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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