Skip to content

Commit a07f19f

Browse files
committed
Merge branch 'ListView-mods'
2 parents 745a2db + f4a9fdb commit a07f19f

9 files changed

+482
-114
lines changed

MainDemo.Wpf/Domain/MainWindowViewModel.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System.Linq;
2-
using System.Windows.Controls;
3-
using MaterialDesignDemo;
1+
using MaterialDesignDemo;
42
using MaterialDesignDemo.Domain;
53
using MaterialDesignThemes.Wpf;
64
using MaterialDesignThemes.Wpf.Transitions;
5+
using System.Windows.Controls;
76

87
namespace MaterialDesignColors.WpfExample.Domain
98
{
@@ -13,14 +12,14 @@ public MainWindowViewModel()
1312
{
1413
DemoItems = new[]
1514
{
16-
new DemoItem("Home", new Home(),
15+
new DemoItem("Home", new Home(),
1716
new []
1817
{
1918
new DocumentationLink(DocumentationLinkType.Wiki, "https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/wiki", "WIKI"),
2019
DocumentationLink.DemoPageLink<Home>()
2120
}
2221
),
23-
new DemoItem("Palette", new PaletteSelector { DataContext = new PaletteSelectorViewModel() },
22+
new DemoItem("Palette", new PaletteSelector { DataContext = new PaletteSelectorViewModel() },
2423
new []
2524
{
2625
DocumentationLink.WikiLink("Brush-Names", "Brushes"),
@@ -30,7 +29,7 @@ public MainWindowViewModel()
3029
DocumentationLink.DemoPageLink<PaletteSelectorViewModel>("Demo View Model"),
3130
DocumentationLink.ApiLink<PaletteHelper>()
3231
}),
33-
new DemoItem("Buttons & Toggles", new Buttons(),
32+
new DemoItem("Buttons & Toggles", new Buttons(),
3433
new []
3534
{
3635
DocumentationLink.WikiLink("Button-Styles", "Buttons"),
@@ -46,10 +45,10 @@ public MainWindowViewModel()
4645
},
4746
new DemoItem("Fields", new TextFields(),
4847
new []
49-
{
48+
{
5049
DocumentationLink.DemoPageLink<TextFields>(),
5150
DocumentationLink.StyleLink("TextBox"),
52-
DocumentationLink.StyleLink("ComboBox"),
51+
DocumentationLink.StyleLink("ComboBox"),
5352
})
5453
{
5554
VerticalScrollBarVisibilityRequirement = ScrollBarVisibility.Auto
@@ -65,7 +64,7 @@ public MainWindowViewModel()
6564
new DemoItem("Sliders", new Sliders(), new []
6665
{
6766
DocumentationLink.DemoPageLink<Sliders>(),
68-
DocumentationLink.StyleLink("Sliders")
67+
DocumentationLink.StyleLink("Sliders")
6968
}),
7069
new DemoItem("Chips", new Chips(), new []
7170
{
@@ -93,7 +92,7 @@ public MainWindowViewModel()
9392
},
9493
new DemoItem("Icon Pack", new IconPack { DataContext = new IconPackViewModel() },
9594
new []
96-
{
95+
{
9796
DocumentationLink.DemoPageLink<IconPack>("Demo View"),
9897
DocumentationLink.DemoPageLink<IconPackViewModel>("Demo View Model"),
9998
DocumentationLink.ApiLink<PackIcon>()
@@ -109,18 +108,22 @@ public MainWindowViewModel()
109108
{
110109
DocumentationLink.DemoPageLink<Lists>("Demo View"),
111110
DocumentationLink.DemoPageLink<ListsAndGridsViewModel>("Demo View Model"),
112-
DocumentationLink.StyleLink("ListBox")
113-
}),
111+
DocumentationLink.StyleLink("ListBox"),
112+
DocumentationLink.StyleLink("ListView")
113+
})
114+
{
115+
VerticalScrollBarVisibilityRequirement = ScrollBarVisibility.Auto
116+
},
114117
new DemoItem("Trees", new Trees { DataContext = new TreesViewModel() },
115118
new []
116-
{
119+
{
117120
DocumentationLink.DemoPageLink<Trees>("Demo View"),
118121
DocumentationLink.DemoPageLink<TreesViewModel>("Demo View Model"),
119122
DocumentationLink.StyleLink("TreeView")
120123
}),
121124
new DemoItem("Grids", new Grids { DataContext = new ListsAndGridsViewModel()},
122125
new []
123-
{
126+
{
124127
DocumentationLink.DemoPageLink<Lists>("Demo View"),
125128
DocumentationLink.DemoPageLink<ListsAndGridsViewModel>("Demo View Model"),
126129
DocumentationLink.StyleLink("DataGrid")
@@ -185,7 +188,7 @@ public MainWindowViewModel()
185188
new DemoItem("Shadows", new Shadows(),
186189
new []
187190
{
188-
DocumentationLink.DemoPageLink<Shadows>(),
191+
DocumentationLink.DemoPageLink<Shadows>(),
189192
}),
190193
};
191194
}

MainDemo.Wpf/Lists.xaml

Lines changed: 100 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,81 +9,116 @@
99
<UserControl.Resources>
1010
<ResourceDictionary>
1111
<ResourceDictionary.MergedDictionaries>
12+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBlock.xaml" />
1213
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
1314
</ResourceDictionary.MergedDictionaries>
1415
</ResourceDictionary>
1516
</UserControl.Resources>
16-
<Grid Margin="8">
17+
<Grid Margin="8" >
1718
<Grid.RowDefinitions>
18-
<RowDefinition/>
19-
<RowDefinition Height="Auto"/>
19+
<RowDefinition Height="Auto" />
20+
<RowDefinition Height="Auto" />
21+
<RowDefinition Height="Auto" />
22+
<RowDefinition Height="Auto" />
23+
<RowDefinition Height="Auto" />
24+
<RowDefinition Height="Auto" />
2025
</Grid.RowDefinitions>
21-
<Grid.ColumnDefinitions>
22-
<ColumnDefinition Width="1*" />
23-
<ColumnDefinition Width="1*" />
24-
<ColumnDefinition Width="1*" />
25-
</Grid.ColumnDefinitions>
26-
<ListBox Grid.Column="0" IsEnabled="{Binding IsChecked, ElementName=EnableListBox}">
27-
<TextBlock>Plain</TextBlock>
28-
<TextBlock>Old</TextBlock>
29-
<TextBlock>ListBox</TextBlock>
30-
<TextBlock>Full of junk</TextBlock>
31-
</ListBox>
32-
<CheckBox Name="EnableListBox" Grid.Row="1" IsChecked="True">Enabled</CheckBox>
33-
<!-- piece together your own items control to create some nice stuff that will make everyone think you are cool. and rightly so, because you are cool. you might even be a hipster for all I know -->
34-
<ItemsControl Grid.Column="1" ItemsSource="{Binding Items1}"
26+
<TextBlock Style="{StaticResource MaterialDesignTitleTextBlock}">ListBox</TextBlock>
27+
<Grid Grid.Row="1">
28+
<Grid.RowDefinitions>
29+
<RowDefinition/>
30+
<RowDefinition Height="Auto"/>
31+
</Grid.RowDefinitions>
32+
<Grid.ColumnDefinitions>
33+
<ColumnDefinition Width="1*" />
34+
<ColumnDefinition Width="1*" />
35+
<ColumnDefinition Width="1*" />
36+
</Grid.ColumnDefinitions>
37+
<ListBox Grid.Column="0" IsEnabled="{Binding IsChecked, ElementName=EnableListBox}">
38+
<TextBlock>Plain</TextBlock>
39+
<TextBlock>Old</TextBlock>
40+
<TextBlock>ListBox</TextBlock>
41+
<TextBlock>Full of junk</TextBlock>
42+
</ListBox>
43+
<CheckBox Name="EnableListBox" Grid.Row="1" IsChecked="True">Enabled</CheckBox>
44+
<!-- piece together your own items control to create some nice stuff that will make everyone think you are cool. and rightly so, because you are cool. you might even be a hipster for all I know -->
45+
<ItemsControl Grid.Column="1" ItemsSource="{Binding Items1}"
3546
Grid.IsSharedSizeScope="True"
3647
Margin="12 0 12 0">
37-
<ItemsControl.ItemTemplate>
38-
<DataTemplate DataType="{x:Type domain:SelectableViewModel}">
39-
<Border x:Name="Border" Padding="8">
40-
<Grid>
41-
<Grid.ColumnDefinitions>
42-
<ColumnDefinition SharedSizeGroup="Checkerz" />
43-
<ColumnDefinition />
44-
</Grid.ColumnDefinitions>
45-
<CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"/>
46-
<StackPanel Margin="8 0 0 0" Grid.Column="1">
47-
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
48-
<TextBlock Text="{Binding Description}" />
49-
</StackPanel>
50-
</Grid>
51-
</Border>
52-
<DataTemplate.Triggers>
53-
<DataTrigger Binding="{Binding IsSelected}" Value="True">
54-
<Setter TargetName="Border" Property="Background" Value="{DynamicResource MaterialDesignSelection}" />
55-
</DataTrigger>
56-
</DataTemplate.Triggers>
57-
</DataTemplate>
58-
</ItemsControl.ItemTemplate>
59-
</ItemsControl>
60-
<!-- and here's another -->
61-
<ItemsControl Grid.Column="2" ItemsSource="{Binding Items2}"
48+
<ItemsControl.ItemTemplate>
49+
<DataTemplate DataType="{x:Type domain:SelectableViewModel}">
50+
<Border x:Name="Border" Padding="8">
51+
<Grid>
52+
<Grid.ColumnDefinitions>
53+
<ColumnDefinition SharedSizeGroup="Checkerz" />
54+
<ColumnDefinition />
55+
</Grid.ColumnDefinitions>
56+
<CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"/>
57+
<StackPanel Margin="8 0 0 0" Grid.Column="1">
58+
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
59+
<TextBlock Text="{Binding Description}" />
60+
</StackPanel>
61+
</Grid>
62+
</Border>
63+
<DataTemplate.Triggers>
64+
<DataTrigger Binding="{Binding IsSelected}" Value="True">
65+
<Setter TargetName="Border" Property="Background" Value="{DynamicResource MaterialDesignSelection}" />
66+
</DataTrigger>
67+
</DataTemplate.Triggers>
68+
</DataTemplate>
69+
</ItemsControl.ItemTemplate>
70+
</ItemsControl>
71+
<!-- and here's another -->
72+
<ItemsControl Grid.Column="2" ItemsSource="{Binding Items2}"
6273
Grid.IsSharedSizeScope="True">
63-
<ItemsControl.ItemTemplate>
64-
<DataTemplate DataType="{x:Type domain:SelectableViewModel}">
65-
<Border x:Name="Border" Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}">
66-
<Grid>
67-
<Grid.ColumnDefinitions>
68-
<ColumnDefinition SharedSizeGroup="Checkerz" />
69-
<ColumnDefinition />
70-
</Grid.ColumnDefinitions>
71-
<ToggleButton VerticalAlignment="Center" IsChecked="{Binding IsSelected}"
74+
<ItemsControl.ItemTemplate>
75+
<DataTemplate DataType="{x:Type domain:SelectableViewModel}">
76+
<Border x:Name="Border" Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}">
77+
<Grid>
78+
<Grid.ColumnDefinitions>
79+
<ColumnDefinition SharedSizeGroup="Checkerz" />
80+
<ColumnDefinition />
81+
</Grid.ColumnDefinitions>
82+
<ToggleButton VerticalAlignment="Center" IsChecked="{Binding IsSelected}"
7283
Style="{StaticResource MaterialDesignActionLightToggleButton}"
7384
Content="{Binding Code}" />
74-
<StackPanel Margin="8 0 0 0" Grid.Column="1">
75-
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
76-
<TextBlock Text="{Binding Description}" />
77-
</StackPanel>
78-
</Grid>
79-
</Border>
80-
<DataTemplate.Triggers>
81-
<DataTrigger Binding="{Binding IsSelected}" Value="True">
82-
<Setter TargetName="Border" Property="Background" Value="{DynamicResource MaterialDesignSelection}" />
83-
</DataTrigger>
84-
</DataTemplate.Triggers>
85-
</DataTemplate>
86-
</ItemsControl.ItemTemplate>
87-
</ItemsControl>
85+
<StackPanel Margin="8 0 0 0" Grid.Column="1">
86+
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
87+
<TextBlock Text="{Binding Description}" />
88+
</StackPanel>
89+
</Grid>
90+
</Border>
91+
<DataTemplate.Triggers>
92+
<DataTrigger Binding="{Binding IsSelected}" Value="True">
93+
<Setter TargetName="Border" Property="Background" Value="{DynamicResource MaterialDesignSelection}" />
94+
</DataTrigger>
95+
</DataTemplate.Triggers>
96+
</DataTemplate>
97+
</ItemsControl.ItemTemplate>
98+
</ItemsControl>
99+
</Grid>
100+
<TextBlock Style="{StaticResource MaterialDesignTitleTextBlock}" Grid.Row="2" Margin="0 32 0 0">ListView</TextBlock>
101+
<ListView Grid.Row="3">
102+
<ListViewItem>
103+
Hello
104+
</ListViewItem>
105+
<ListViewItem>
106+
World
107+
</ListViewItem>
108+
<ListViewItem>
109+
:)
110+
</ListViewItem>
111+
</ListView>
112+
<TextBlock Style="{StaticResource MaterialDesignTitleTextBlock}" Grid.Row="4" Margin="0 32 0 0">ListView.GridView</TextBlock>
113+
<ListView Grid.Row="5" ItemsSource="{Binding Items1}">
114+
<ListView.View>
115+
<GridView>
116+
<GridViewColumn DisplayMemberBinding="{Binding Code}" Header="Code" />
117+
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name" />
118+
<GridViewColumn DisplayMemberBinding="{Binding Description}" Header="Description" />
119+
</GridView>
120+
</ListView.View>
121+
</ListView>
88122
</Grid>
123+
89124
</UserControl>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Controls;
5+
using System.Windows.Data;
6+
7+
namespace MaterialDesignThemes.Wpf.Converters
8+
{
9+
/// <summary>
10+
/// Helps coerce the correct item container style for a <see cref="ListView"/>, according to whether the list is displaying in standard mode, or using a <see cref="ListView.View"/>, such as a <see cref="GridView"/>.
11+
/// </summary>
12+
public class ListViewGridViewConverter : IValueConverter
13+
{
14+
/// <summary>
15+
/// Item container style to use when <see cref="ListView.View"/> is <c>null</c>.
16+
/// </summary>
17+
public object DefaultValue { get; set; }
18+
19+
/// <summary>
20+
/// Item container style to use when <see cref="ListView.View"/> is not <c>null</c>, typically when a <see cref="GridView"/> is applied.
21+
/// </summary>
22+
public object ViewValue { get; set; }
23+
24+
/// <summary>
25+
/// Returns the item container <see cref="Style"/> to use for a <see cref="ListView"/>.
26+
/// </summary>
27+
/// <param name="value">Should be a <see cref="ListView"/> or <see cref="ViewBase"/> instance.</param>
28+
/// <param name="targetType"></param>
29+
/// <param name="parameter"></param>
30+
/// <param name="culture"></param>
31+
/// <returns></returns>
32+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
33+
{
34+
var listView = value as ListView;
35+
if (listView != null)
36+
{
37+
return listView.View != null ? ViewValue : DefaultValue;
38+
}
39+
40+
return value is ViewBase ? ViewValue : DefaultValue;
41+
}
42+
43+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
44+
{
45+
return Binding.DoNothing;
46+
}
47+
}
48+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace MaterialDesignThemes.Wpf
5+
{
6+
public static class ListViewAssist
7+
{
8+
public static readonly DependencyProperty ListViewItemPaddingProperty = DependencyProperty.RegisterAttached(
9+
"ListViewItemPadding",
10+
typeof(Thickness),
11+
typeof(ListViewAssist),
12+
new FrameworkPropertyMetadata(new Thickness(8, 8, 8, 8), FrameworkPropertyMetadataOptions.Inherits));
13+
14+
public static void SetListViewItemPadding(DependencyObject element, Thickness value)
15+
{
16+
element.SetValue(ListViewItemPaddingProperty, value);
17+
}
18+
19+
public static Thickness GetListViewItemPadding(DependencyObject element)
20+
{
21+
return (Thickness)element.GetValue(ListViewItemPaddingProperty);
22+
}
23+
}
24+
}

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@
134134
<SubType>Designer</SubType>
135135
<Generator>MSBuild:Compile</Generator>
136136
</Page>
137+
<Page Include="Themes\MaterialDesignTheme.ListView.xaml">
138+
<SubType>Designer</SubType>
139+
<Generator>MSBuild:Compile</Generator>
140+
</Page>
137141
<Page Include="Themes\MaterialDesignTheme.Menu.xaml">
138142
<SubType>Designer</SubType>
139143
<Generator>MSBuild:Compile</Generator>
@@ -246,6 +250,10 @@
246250
<SubType>Designer</SubType>
247251
<Generator>MSBuild:Compile</Generator>
248252
</Page>
253+
<Page Include="Themes\MaterialDesignTheme.Thumb.xaml">
254+
<Generator>MSBuild:Compile</Generator>
255+
<SubType>Designer</SubType>
256+
</Page>
249257
</ItemGroup>
250258
<ItemGroup>
251259
<Compile Include="Badged.cs" />
@@ -271,6 +279,7 @@
271279
<Compile Include="Converters\CircularProgressBar\StartPointConverter.cs" />
272280
<Compile Include="Converters\ClockItemIsCheckedConverter.cs" />
273281
<Compile Include="Converters\ClockLineConverter.cs" />
282+
<Compile Include="Converters\ListViewItemContainerStyleConverter.cs" />
274283
<Compile Include="Converters\RangePositionConverterConverter.cs" />
275284
<Compile Include="Converters\DrawerOffsetConverter.cs" />
276285
<Compile Include="Converters\EqualityToVisibilityConverter.cs" />
@@ -309,6 +318,7 @@
309318
<Compile Include="IconType.cs" />
310319
<Compile Include="ISnackbarMessageQueue.cs" />
311320
<Compile Include="ListBoxAssist.cs" />
321+
<Compile Include="ListViewAssist.cs" />
312322
<Compile Include="MessageQueueExtension.cs" />
313323
<Compile Include="PackIconExtension.cs" />
314324
<Compile Include="Palette.cs" />

0 commit comments

Comments
 (0)