-
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.
- Loading branch information
Showing
4 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
MaterialDesignThemes.UITests/WPF/TreeListViews/TreeListViewTemplateSelector.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,33 @@ | ||
<UserControl x:Class="MaterialDesignThemes.UITests.WPF.TreeListViews.TreeListViewTemplateSelector" | ||
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" | ||
xmlns:local="clr-namespace:MaterialDesignThemes.UITests.WPF.TreeListViews" | ||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" | ||
xmlns:sys="clr-namespace:System;assembly=mscorlib" | ||
mc:Ignorable="d" | ||
DataContext="{Binding RelativeSource={RelativeSource Self}}" | ||
d:DesignHeight="450" d:DesignWidth="800"> | ||
<materialDesign:TreeListView | ||
x:Name="TreeListView" | ||
ItemsSource="{Binding Items}"> | ||
<materialDesign:TreeListView.ItemTemplateSelector> | ||
<local:TypeTemplateSelector> | ||
<local:TypeTemplateSelector.NumberTemplate> | ||
<HierarchicalDataTemplate DataType="{x:Type local:TreeItem}" | ||
ItemsSource="{Binding Children}"> | ||
<TextBlock Text="{Binding Value}" Foreground="Red" /> | ||
</HierarchicalDataTemplate> | ||
</local:TypeTemplateSelector.NumberTemplate> | ||
|
||
<local:TypeTemplateSelector.StringTemplate> | ||
<HierarchicalDataTemplate DataType="{x:Type local:TreeItem}" | ||
ItemsSource="{Binding Children}"> | ||
<TextBlock Text="{Binding Value}" Foreground="Blue" /> | ||
</HierarchicalDataTemplate> | ||
</local:TypeTemplateSelector.StringTemplate> | ||
</local:TypeTemplateSelector> | ||
</materialDesign:TreeListView.ItemTemplateSelector> | ||
</materialDesign:TreeListView> | ||
</UserControl> |
51 changes: 51 additions & 0 deletions
51
MaterialDesignThemes.UITests/WPF/TreeListViews/TreeListViewTemplateSelector.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,51 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace MaterialDesignThemes.UITests.WPF.TreeListViews; | ||
|
||
/// <summary> | ||
/// Interaction logic for TreeListViewTemplateSelector.xaml | ||
/// </summary> | ||
public partial class TreeListViewTemplateSelector | ||
{ | ||
public ObservableCollection<TreeItem> Items { get; } = new(); | ||
|
||
|
||
public TreeListViewTemplateSelector() | ||
{ | ||
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)); | ||
} | ||
Items.Add(item); | ||
} | ||
} | ||
} | ||
|
||
public class TypeTemplateSelector : DataTemplateSelector | ||
{ | ||
public DataTemplate? NumberTemplate { get; set; } | ||
public DataTemplate? StringTemplate { get; set; } | ||
|
||
public override DataTemplate? SelectTemplate(object? item, DependencyObject container) | ||
{ | ||
if (item is TreeItem treeItem) | ||
{ | ||
if (int.TryParse(treeItem.Value, out _)) | ||
{ | ||
return NumberTemplate; | ||
} | ||
return StringTemplate; | ||
} | ||
return null; | ||
} | ||
} |
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