-
-
Save erkantaylan/1830ed54891c90bc818f2820e3e0d030 to your computer and use it in GitHub Desktop.
Folder Tree WPF Control: Part 1 - Lazy Loading
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
<TreeView ItemsSource="{Binding Path=Drives}" TreeViewItem.Expanded="FolderTree_Expanded"> | |
<TreeView.ItemContainerStyle> | |
<Style TargetType="TreeViewItem"> | |
<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" /> | |
</Style> | |
</TreeView.ItemContainerStyle> | |
<TreeView.ItemTemplate> | |
<HierarchicalDataTemplate ItemsSource="{Binding Path=Folders}"> | |
<TextBlock Text="{Binding Path=Label}" /> | |
</HierarchicalDataTemplate> | |
</TreeView.ItemTemplate> | |
</TreeView> |
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
public partial class FolderTree : UserControl | |
{ | |
... | |
private void FolderTree_Expanded(object sender, RoutedEventArgs e) | |
{ | |
var treeViewItem = (TreeViewItem)e.OriginalSource; | |
var node = (FolderTreeItem)treeViewItem.Header; | |
node.LoadChildren(); | |
} | |
} |
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.Model | |
{ | |
public abstract class FolderTreeItem : ViewModelBase | |
{ | |
private bool _isExpanded; | |
public bool IsExpanded | |
{ | |
get | |
{ | |
return _isExpanded; | |
} | |
set | |
{ | |
_isExpanded = value; | |
OnPropertyChanged("IsExpanded"); | |
} | |
} | |
public abstract void LoadChildren(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment