-
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.
Fix tree list view bug and demo apps (#3350)
* Fix null propagation issue * Fix demo app pages * Fixing issue with implicit data tempaltes Using a custom content presenter we can retrieve the template. * Removing commented code --------- Co-authored-by: Kevin Bost <[email protected]>
- Loading branch information
1 parent
4b14f71
commit 5f73f11
Showing
13 changed files
with
425 additions
and
107 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
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
33 changes: 33 additions & 0 deletions
33
MaterialDesignThemes.UITests/WPF/TreeListViews/TestableCollection.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,33 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Collections.Specialized; | ||
using System.Threading; | ||
|
||
namespace MaterialDesignThemes.UITests.WPF.TreeListViews; | ||
|
||
public class TestableCollection<T> : ObservableCollection<T> | ||
{ | ||
private int _blockCollectionChanges; | ||
|
||
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) | ||
{ | ||
if (Interlocked.CompareExchange(ref _blockCollectionChanges, 0, 0) == 0) | ||
{ | ||
base.OnCollectionChanged(e); | ||
} | ||
} | ||
|
||
public void ReplaceAllItems(params T[] newItems) | ||
{ | ||
Interlocked.Exchange(ref _blockCollectionChanges, 1); | ||
|
||
Clear(); | ||
foreach (T newItem in newItems) | ||
{ | ||
Add(newItem); | ||
} | ||
|
||
Interlocked.Exchange(ref _blockCollectionChanges, 0); | ||
|
||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
MaterialDesignThemes.UITests/WPF/TreeListViews/TreeItem.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,20 @@ | ||
using System.Diagnostics; | ||
|
||
namespace MaterialDesignThemes.UITests.WPF.TreeListViews; | ||
|
||
[DebuggerDisplay("{Value} (Children: {Children.Count})")] | ||
public class TreeItem | ||
{ | ||
public string Value { get; } | ||
|
||
public TreeItem? Parent { get; } | ||
|
||
//NB: making the assumption changes occur ont he UI thread | ||
public TestableCollection<TreeItem> Children { get; } = new(); | ||
|
||
public TreeItem(string value, TreeItem? parent) | ||
{ | ||
Value = value; | ||
Parent = parent; | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
MaterialDesignThemes.UITests/WPF/TreeListViews/TreeListViewImplicitTemplate.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,35 @@ | ||
<UserControl x:Class="MaterialDesignThemes.UITests.WPF.TreeListViews.TreeListViewImplicitTemplate" | ||
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" | ||
mc:Ignorable="d" | ||
DataContext="{Binding RelativeSource={RelativeSource Self}}" | ||
d:DesignHeight="450" d:DesignWidth="800"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<materialDesign:TreeListView | ||
x:Name="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> | ||
<StackPanel Grid.Row="1" Orientation="Horizontal"> | ||
<Button Content="Add" Click="Add_OnClick" /> | ||
<Button Content="Remove" Click="Remove_OnClick" /> | ||
<Button Content="Replace" Click="Replace_OnClick" /> | ||
<Button Content="Down" Click="MoveDown_OnClick" /> | ||
<Button Content="Up" Click="MoveUp_OnClick" /> | ||
<Button Content="Reset" Click="Reset_OnClick" /> | ||
</StackPanel> | ||
</Grid> | ||
</UserControl> |
Oops, something went wrong.