Skip to content

Commit 1d8a0d8

Browse files
committed
more demo tidy up [skip ci]
1 parent cfe56d1 commit 1d8a0d8

File tree

8 files changed

+221
-163
lines changed

8 files changed

+221
-163
lines changed

MaterialDesignColors.WpfExample/Domain/ListFieldsViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
namespace MaterialDesignColors.WpfExample.Domain
88
{
9-
public class ListsWindowViewModel : INotifyPropertyChanged
9+
public class ListsAndGridsViewModel : INotifyPropertyChanged
1010
{
1111
private readonly ObservableCollection<SelectableViewModel> _items1;
1212
private readonly ObservableCollection<SelectableViewModel> _items2;
1313
private readonly ObservableCollection<SelectableViewModel> _items3;
1414
private bool? _isAllItems3Selected;
1515

16-
public ListsWindowViewModel()
16+
public ListsAndGridsViewModel()
1717
{
1818
_items1 = CreateData();
1919
_items2 = CreateData();
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Grids"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:MaterialDesignColors.WpfExample"
7+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
8+
mc:Ignorable="d"
9+
d:DesignHeight="300" d:DesignWidth="300">
10+
<UserControl.Resources>
11+
<ResourceDictionary>
12+
<ResourceDictionary.MergedDictionaries>
13+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.DataGrid.xaml" />
14+
</ResourceDictionary.MergedDictionaries>
15+
</ResourceDictionary>
16+
</UserControl.Resources>
17+
<ScrollViewer>
18+
<StackPanel>
19+
<TextBlock>Custom Columns</TextBlock>
20+
<DataGrid Margin="0 8 0 0" ItemsSource="{Binding Items3}" CanUserSortColumns="True" CanUserAddRows="False" AutoGenerateColumns="False">
21+
<DataGrid.Columns>
22+
<DataGridCheckBoxColumn Binding="{Binding IsSelected}"
23+
ElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnStyle}"
24+
EditingElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnEditingStyle}">
25+
<DataGridCheckBoxColumn.Header>
26+
<!--padding to allow hit test to pass thru for sorting -->
27+
<Border Background="Transparent" Padding="6 0 6 0" HorizontalAlignment="Center">
28+
<CheckBox HorizontalAlignment="Center"
29+
DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=DataContext}"
30+
IsChecked="{Binding IsAllItems3Selected}" />
31+
</Border>
32+
</DataGridCheckBoxColumn.Header>
33+
</DataGridCheckBoxColumn>
34+
<DataGridTextColumn Binding="{Binding Code}"
35+
Header="Code"
36+
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
37+
/>
38+
<!-- if you want to use the pop up style (MaterialDesignDataGridTextColumnPopupEditingStyle), you must use MaterialDataGridTextColumn -->
39+
<wpf:MaterialDataGridTextColumn Binding="{Binding Name}"
40+
Header="Name"
41+
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}"
42+
/>
43+
<!-- set a max length to get an indicator in the editor -->
44+
<wpf:MaterialDataGridTextColumn Binding="{Binding Description}"
45+
Header="Description"
46+
MaxLength="255"
47+
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}"
48+
/>
49+
<wpf:MaterialDataGridTextColumn Binding="{Binding Numeric}"
50+
Header="Numeric"
51+
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}">
52+
<DataGridTextColumn.HeaderStyle>
53+
<Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
54+
<Setter Property="HorizontalAlignment" Value="Right" />
55+
</Style>
56+
</DataGridTextColumn.HeaderStyle>
57+
<DataGridTextColumn.ElementStyle>
58+
<Style TargetType="{x:Type TextBlock}">
59+
<Setter Property="HorizontalAlignment" Value="Right" />
60+
</Style>
61+
</DataGridTextColumn.ElementStyle>
62+
</wpf:MaterialDataGridTextColumn>
63+
64+
<!-- use custom combo box column to get better combos. Use ItemsSourceBinding as your binding template to be applied to each combo -->
65+
<wpf:MaterialDataGridComboBoxColumn Header="Food"
66+
SelectedValueBinding="{Binding Food}"
67+
ItemsSourceBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Foods}" />
68+
</DataGrid.Columns>
69+
</DataGrid>
70+
<TextBlock Margin="0 24 0 0" >Auto Generated Columns</TextBlock>
71+
<DataGrid Margin="0 8 0 0" ItemsSource="{Binding Items3}" CanUserSortColumns="True" CanUserAddRows="False" />
72+
</StackPanel>
73+
</ScrollViewer>
74+
</UserControl>

MaterialDesignColors.WpfExample/ListsWindow.xaml.cs renamed to MaterialDesignColors.WpfExample/Grids.xaml.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,19 @@
1010
using System.Windows.Input;
1111
using System.Windows.Media;
1212
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
1314
using System.Windows.Shapes;
14-
using MaterialDesignColors.WpfExample.Domain;
1515

1616
namespace MaterialDesignColors.WpfExample
1717
{
1818
/// <summary>
19-
/// Interaction logic for ListsWindow.xaml
19+
/// Interaction logic for Grids.xaml
2020
/// </summary>
21-
public partial class ListsWindow : Window
21+
public partial class Grids : UserControl
2222
{
23-
public ListsWindow()
23+
public Grids()
2424
{
2525
InitializeComponent();
26-
27-
DataContext = new ListsWindowViewModel();
2826
}
2927
}
3028
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<UserControl x:Class="MaterialDesignColors.WpfExample.Lists"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:MaterialDesignColors.WpfExample"
7+
xmlns:domain="clr-namespace:MaterialDesignColors.WpfExample.Domain"
8+
mc:Ignorable="d"
9+
d:DesignHeight="300" d:DesignWidth="300">
10+
<UserControl.Resources>
11+
<ResourceDictionary>
12+
<ResourceDictionary.MergedDictionaries>
13+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
14+
</ResourceDictionary.MergedDictionaries>
15+
</ResourceDictionary>
16+
</UserControl.Resources>
17+
<Grid Margin="8">
18+
<Grid.ColumnDefinitions>
19+
<ColumnDefinition Width="1*" />
20+
<ColumnDefinition Width="1*" />
21+
<ColumnDefinition Width="1*" />
22+
</Grid.ColumnDefinitions>
23+
<ListBox Grid.Column="0">
24+
<TextBlock>Plain</TextBlock>
25+
<TextBlock>Old</TextBlock>
26+
<TextBlock>ListBox</TextBlock>
27+
<TextBlock>Full of junk</TextBlock>
28+
</ListBox>
29+
<!-- 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 -->
30+
<ItemsControl Grid.Column="1" ItemsSource="{Binding Items1}"
31+
Grid.IsSharedSizeScope="True"
32+
Margin="12 0 12 0">
33+
<ItemsControl.ItemTemplate>
34+
<DataTemplate DataType="{x:Type domain:SelectableViewModel}">
35+
<Border x:Name="Border" Padding="8">
36+
<Grid>
37+
<Grid.ColumnDefinitions>
38+
<ColumnDefinition SharedSizeGroup="Checkerz" />
39+
<ColumnDefinition />
40+
</Grid.ColumnDefinitions>
41+
<CheckBox VerticalAlignment="Center" IsChecked="{Binding IsSelected}"/>
42+
<StackPanel Margin="8 0 0 0" Grid.Column="1">
43+
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
44+
<TextBlock Text="{Binding Description}" />
45+
</StackPanel>
46+
</Grid>
47+
</Border>
48+
<DataTemplate.Triggers>
49+
<DataTrigger Binding="{Binding IsSelected}" Value="True">
50+
<Setter TargetName="Border" Property="Background" Value="{DynamicResource MaterialDesignSelection}" />
51+
</DataTrigger>
52+
</DataTemplate.Triggers>
53+
</DataTemplate>
54+
</ItemsControl.ItemTemplate>
55+
</ItemsControl>
56+
<!-- and here's another -->
57+
<ItemsControl Grid.Column="2" ItemsSource="{Binding Items2}"
58+
Grid.IsSharedSizeScope="True">
59+
<ItemsControl.ItemTemplate>
60+
<DataTemplate DataType="{x:Type domain:SelectableViewModel}">
61+
<Border x:Name="Border" Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}">
62+
<Grid>
63+
<Grid.ColumnDefinitions>
64+
<ColumnDefinition SharedSizeGroup="Checkerz" />
65+
<ColumnDefinition />
66+
</Grid.ColumnDefinitions>
67+
<ToggleButton VerticalAlignment="Center" IsChecked="{Binding IsSelected}"
68+
Style="{StaticResource MaterialDesignActionLightToggleButton}"
69+
Content="{Binding Code}" />
70+
<StackPanel Margin="8 0 0 0" Grid.Column="1">
71+
<TextBlock FontWeight="Bold" Text="{Binding Name}" />
72+
<TextBlock Text="{Binding Description}" />
73+
</StackPanel>
74+
</Grid>
75+
</Border>
76+
<DataTemplate.Triggers>
77+
<DataTrigger Binding="{Binding IsSelected}" Value="True">
78+
<Setter TargetName="Border" Property="Background" Value="{DynamicResource MaterialDesignSelection}" />
79+
</DataTrigger>
80+
</DataTemplate.Triggers>
81+
</DataTemplate>
82+
</ItemsControl.ItemTemplate>
83+
</ItemsControl>
84+
</Grid>
85+
</UserControl>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace MaterialDesignColors.WpfExample
17+
{
18+
/// <summary>
19+
/// Interaction logic for Lists.xaml
20+
/// </summary>
21+
public partial class Lists : UserControl
22+
{
23+
public Lists()
24+
{
25+
InitializeComponent();
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)