-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing TreeListView to work with non-generic collections
Specifically ICollectionView
- Loading branch information
Showing
7 changed files
with
123 additions
and
39 deletions.
There are no files selected for viewing
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
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
19 changes: 19 additions & 0 deletions
19
MaterialDesignThemes.UITests/WPF/TreeListViews/TreeListViewWithCollectionView.xaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<UserControl x:Class="MaterialDesignThemes.UITests.WPF.TreeListViews.TreeListViewWithCollectionView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:MaterialDesignThemes.UITests.WPF.TreeListViews" | ||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
DataContext="{Binding RelativeSource={RelativeSource Self}}" | ||
mc:Ignorable="d"> | ||
<materialDesign:TreeListView ItemsSource="{Binding Items}"> | ||
<materialDesign:TreeListView.Resources> | ||
<HierarchicalDataTemplate DataType="{x:Type local:TreeItem}" ItemsSource="{Binding Children}"> | ||
<TextBlock Text="{Binding Value}" /> | ||
</HierarchicalDataTemplate> | ||
</materialDesign:TreeListView.Resources> | ||
</materialDesign:TreeListView> | ||
</UserControl> |
37 changes: 37 additions & 0 deletions
37
MaterialDesignThemes.UITests/WPF/TreeListViews/TreeListViewWithCollectionView.xaml.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Windows.Data; | ||
|
||
namespace MaterialDesignThemes.UITests.WPF.TreeListViews; | ||
|
||
/// <summary> | ||
/// Interaction logic for TreeListViewWithCollectionView.xaml | ||
/// </summary> | ||
public partial class TreeListViewWithCollectionView : UserControl | ||
{ | ||
private ObservableCollection<TreeItem> ItemsSource { get; } = new(); | ||
|
||
public ICollectionView Items { get; } | ||
|
||
public TreeListViewWithCollectionView() | ||
{ | ||
Items = CollectionViewSource.GetDefaultView(ItemsSource); | ||
|
||
InitializeComponent(); | ||
|
||
AddChildren("Foo"); | ||
AddChildren("42"); | ||
AddChildren("24", "a", "b", "c"); | ||
AddChildren("Bar", "1", "2", "3"); | ||
|
||
void AddChildren(string root, params string[] children) | ||
{ | ||
TreeItem item = new(root, null); | ||
foreach (string child in children) | ||
{ | ||
item.Children.Add(new TreeItem(child, item)); | ||
} | ||
ItemsSource.Add(item); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.