forked from MaterialDesignInXAML/MaterialDesignInXamlToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataGrids.xaml
188 lines (167 loc) · 9.83 KB
/
DataGrids.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<UserControl x:Class="MaterialDesignDemo.DataGrids"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:domain="clr-namespace:MaterialDesignDemo.Domain"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:smtx="clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"
d:DataContext="{d:DesignInstance domain:ListsAndGridsViewModel}"
d:DesignHeight="300"
d:DesignWidth="600"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.DataGrid.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}" Text="Custom Columns" />
<TextBlock Margin="25,0,10,0"
VerticalAlignment="Center"
Style="{StaticResource MaterialDesignBody1TextBlock}"
Text="SelectionUnit:" />
<ComboBox x:Name="selectionUnitComboBox"
VerticalAlignment="Center"
ItemsSource="{Binding SelectionUnits}"
SelectedIndex="0" />
</StackPanel>
<FrameworkElement x:Name="DataContextProxy" DataContext="{Binding}"/>
<smtx:XamlDisplay UniqueKey="grids_1">
<DataGrid AutoGenerateColumns="False"
CanUserAddRows="False"
HeadersVisibility="All"
ItemsSource="{Binding Items1}"
SelectionUnit="{Binding ElementName=selectionUnitComboBox, Path=SelectedValue}">
<DataGrid.Columns>
<!-- by default a DataGridCheckBoxColumn will have the MaterialDesignDataGridCheckBoxColumnStyle and MaterialDesignDataGridCheckBoxColumnEditingStyle applied. See DataGridAssist.ApplyMaterialDesignColumnStyles attached property -->
<DataGridCheckBoxColumn Binding="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}">
<DataGridCheckBoxColumn.Header>
<Border Background="Transparent">
<CheckBox IsChecked="{Binding DataContext.IsAllItems1Selected, Source={x:Reference DataContextProxy}}" />
</Border>
</DataGridCheckBoxColumn.Header>
<DataGridCheckBoxColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGridCheckBoxColumn.HeaderStyle>
</DataGridCheckBoxColumn>
<!-- by default a DataGridTextColumn will have the MaterialDesignDataGridTextColumnStyle and MaterialDesignDataGridTextColumnEditingStyle applied. See DataGridAssist.ApplyMaterialDesignColumnStyles attached property -->
<DataGridTextColumn Binding="{Binding Code}" Header="Code" />
<!-- if you want to use the pop up style (MaterialDesignDataGridTextColumnPopupEditingStyle), you must use MaterialDataGridTextColumn -->
<materialDesign:DataGridTextColumn EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}"
ElementStyle="{StaticResource MaterialDesignDataGridTextColumnStyle}"
Header="Name">
<materialDesign:DataGridTextColumn.Binding>
<Binding Path="Name">
<Binding.ValidationRules>
<domain:NotEmptyValidationRule />
</Binding.ValidationRules>
</Binding>
</materialDesign:DataGridTextColumn.Binding>
</materialDesign:DataGridTextColumn>
<!-- set a max length to get an indicator in the editor -->
<DataGridTextColumn Header="Description">
<DataGridTextColumn.Binding>
<Binding Path="Description">
<Binding.ValidationRules>
<domain:NotEmptyValidationRule />
</Binding.ValidationRules>
</Binding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
<materialDesign:DataGridTextColumn Width="120"
Binding="{Binding Numeric}"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}"
Header="Number with long header">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}"
TextAlignment="Right"
TextWrapping="Wrap" />
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="HorizontalContentAlignment" Value="Right" />
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource MaterialDesignDataGridTextColumnStyle}">
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
</DataGridTextColumn.ElementStyle>
</materialDesign:DataGridTextColumn>
<!-- use custom combo box column to get better combos. Use ItemsSourceBinding as your binding template to be applied to each combo -->
<materialDesign:DataGridComboBoxColumn Width="100"
Header="Food with long header"
IsEditable="True"
ItemsSourceBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Foods}"
SelectedValueBinding="{Binding Food}">
<!--Setting the editing element style allows access to all of the combo box's properties
<materialDesign:MaterialDataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox" BasedOn="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type ComboBox}, ResourceId=MaterialDataGridComboBoxColumnEditingStyle}}" >
<Setter Property="IsEditable" Value="True" />
</Style>
</materialDesign:MaterialDataGridComboBoxColumn.EditingElementStyle>
-->
</materialDesign:DataGridComboBoxColumn>
<materialDesign:DataGridComboBoxColumn Header="ComboBox with long list"
ItemsSourceBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Files}"
SelectedValueBinding="{Binding Files}" />
<DataGridTemplateColumn Header="Template Column">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="{x:Type domain:SelectableViewModel}">
<TextBlock FontSize="14"
FontStyle="Italic"
Text="{Binding Name}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate DataType="{x:Type domain:SelectableViewModel}">
<TextBox Foreground="{DynamicResource SecondaryHueMidBrush}" Text="{Binding Name}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</smtx:XamlDisplay>
<StackPanel Margin="0,15,0,0" Orientation="Horizontal">
<materialDesign:PackIcon Margin="0,0,5,0" Kind="Information" />
<TextBlock>DataGridComboBoxColumns are virtualized by default in the library</TextBlock>
</StackPanel>
<TextBlock Margin="0,24,0,0"
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
Text="Auto Generated Columns" />
<smtx:XamlDisplay UniqueKey="grids_2">
<DataGrid CanUserAddRows="False"
ItemsSource="{Binding Items2}"
SelectionMode="Extended"
SelectionUnit="Cell" />
</smtx:XamlDisplay>
<TextBlock Margin="0,24,0,0"
Style="{StaticResource MaterialDesignHeadline6TextBlock}"
Text="Custom Padding" />
<smtx:XamlDisplay UniqueKey="grids_3">
<DataGrid materialDesign:DataGridAssist.CellPadding="4 2 2 2"
materialDesign:DataGridAssist.ColumnHeaderPadding="4 2 2 2"
CanUserAddRows="False"
CanUserSortColumns="False"
ItemsSource="{Binding Items3}" />
</smtx:XamlDisplay>
<TextBlock Margin="0,24,0,0"
Style="{StaticResource MaterialDesignHeadline6TextBlock}"
Text="Custom Selected Cell Border Brush" />
<smtx:XamlDisplay UniqueKey="grids_4">
<DataGrid materialDesign:DataGridAssist.SelectedCellBorderBrush="Crimson"
CanUserAddRows="False"
ItemsSource="{Binding Items4}" />
</smtx:XamlDisplay>
</StackPanel>
</UserControl>