Skip to content

Commit 38ff3e5

Browse files
author
MohammadHadi Attarieh
committed
implement treedatagrid
1 parent 122a534 commit 38ff3e5

File tree

5 files changed

+263
-44
lines changed

5 files changed

+263
-44
lines changed

src/MainDemo.Wpf/Trees.xaml

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
88
xmlns:smtx="clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"
9+
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf"
910
d:DataContext="{d:DesignInstance domain:TreesViewModel}"
1011
d:DesignHeight="1080"
1112
d:DesignWidth="1920"
@@ -18,6 +19,8 @@
1819
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml" />
1920
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBlock.xaml" />
2021
</ResourceDictionary.MergedDictionaries>
22+
23+
<converters:TreeListViewIndentConverter x:Key="TreeListViewIndentConverter" />
2124
</ResourceDictionary>
2225
</UserControl.Resources>
2326

@@ -216,18 +219,18 @@
216219
<materialDesign:TreeListView.Resources>
217220
<HierarchicalDataTemplate DataType="{x:Type domain:TestItem}"
218221
ItemsSource="{Binding Items, Mode=OneTime}">
219-
<TextBlock Margin="3,2" Text="{Binding Name, Mode=OneTime}" />
222+
<!--<TextBlock Margin="3,2" Text="{Binding Name, Mode=OneTime}" />-->
220223
</HierarchicalDataTemplate>
221224

222225
<HierarchicalDataTemplate DataType="{x:Type domain:MovieCategory}"
223226
ItemsSource="{Binding Movies, Mode=OneTime}">
224-
<TextBlock Margin="3,2" Text="{Binding Name, Mode=OneTime}" />
227+
<!--<TextBlock Margin="3,2" Text="{Binding Name, Mode=OneTime}" />-->
225228
</HierarchicalDataTemplate>
226229

227230
<DataTemplate DataType="{x:Type domain:Movie}">
228-
<TextBlock Margin="3,2"
231+
<!--<TextBlock Margin="3,2"
229232
Text="{Binding Name, Mode=OneTime}"
230-
ToolTip="{Binding Director, Mode=OneTime}" />
233+
ToolTip="{Binding Director, Mode=OneTime}" />-->
231234
</DataTemplate>
232235
</materialDesign:TreeListView.Resources>
233236

@@ -244,6 +247,48 @@
244247
<Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
245248
</Style>
246249
</materialDesign:TreeListView.ItemContainerStyle>
250+
251+
<materialDesign:TreeListView.Columns>
252+
<GridViewColumnCollection>
253+
<GridViewColumn Width="250"
254+
Header="Name">
255+
<GridViewColumn.CellTemplate>
256+
<DataTemplate>
257+
<materialDesign:TreeListViewCell>
258+
<StackPanel Orientation="Horizontal">
259+
<StackPanel.Margin>
260+
<MultiBinding Converter="{StaticResource TreeListViewIndentConverter}">
261+
<Binding Path="LevelIndentSize"
262+
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type materialDesign:TreeListView}}" />
263+
<Binding Path="Level"
264+
RelativeSource="{RelativeSource AncestorType={x:Type materialDesign:TreeListViewItem}}" />
265+
</MultiBinding>
266+
</StackPanel.Margin>
267+
268+
<ToggleButton IsChecked="{Binding RelativeSource={RelativeSource AncestorType=materialDesign:TreeListViewItem, Mode=FindAncestor}, Path=IsExpanded}"
269+
Style="{StaticResource MaterialDesignTreeListViewToggleButtonStyle}" />
270+
271+
<TextBlock VerticalAlignment="Center"
272+
Text="{Binding Name, Mode=OneTime}" />
273+
</StackPanel>
274+
</materialDesign:TreeListViewCell>
275+
</DataTemplate>
276+
</GridViewColumn.CellTemplate>
277+
</GridViewColumn>
278+
279+
<GridViewColumn Width="100"
280+
Header="Count">
281+
<GridViewColumn.CellTemplate>
282+
<DataTemplate>
283+
<materialDesign:TreeListViewCell>
284+
<TextBlock VerticalAlignment="Center"
285+
Text="{Binding Items.Count, Mode=OneWay}" />
286+
</materialDesign:TreeListViewCell>
287+
</DataTemplate>
288+
</GridViewColumn.CellTemplate>
289+
</GridViewColumn>
290+
</GridViewColumnCollection>
291+
</materialDesign:TreeListView.Columns>
247292
</materialDesign:TreeListView>
248293
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Right">
249294
<Button Command="{Binding AddListTreeItemCommand}"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Globalization;
2+
using System.Windows.Data;
3+
using System.Windows.Media;
4+
5+
namespace MaterialDesignThemes.Wpf.Converters;
6+
7+
public class TreeListViewGridLineBrushConverter : IValueConverter
8+
{
9+
public SolidColorBrush DefaultBrush { get; set; } = Brushes.Transparent;
10+
public SolidColorBrush SelectedBrush { get; set; } = Brushes.Transparent;
11+
12+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
13+
{
14+
if (value is not bool isSelected)
15+
{
16+
return Binding.DoNothing;
17+
}
18+
19+
return isSelected ? SelectedBrush : DefaultBrush;
20+
}
21+
22+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
23+
}

0 commit comments

Comments
 (0)