/
MainWindow.xaml.cs
63 lines (55 loc) · 2.72 KB
/
MainWindow.xaml.cs
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
using System.Windows;
using System.Windows.Controls;
using DevExpress.Xpf.Grid;
namespace Forbid_Expand_Collapse {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
grid.ItemsSource = Invoice.GetData();
}
void OnEndGrouping(object sender, RoutedEventArgs e) {
if (grid.Columns[nameof(Invoice.Status)].GroupIndex == 0) {
var childRow = grid.FindRowByValue(grid.Columns[nameof(Invoice.Status)], InvoiceStatus.Invalidated);
var groupRow = grid.GetParentRowHandle(childRow);
grid.ExpandGroupRow(groupRow);
childRow = grid.FindRowByValue(grid.Columns[nameof(Invoice.Status)], InvoiceStatus.Delivered);
groupRow = grid.GetParentRowHandle(childRow);
grid.CollapseGroupRow(groupRow);
}
}
void OnGroupRowCollapsing(object sender, RowAllowEventArgs e) {
if (e.Row != null && grid.GetGroupRowValue(e.RowHandle).Equals(InvoiceStatus.Invalidated))
e.Allow = false;
}
void OnGroupRowCollapsed(object sender, RowEventArgs e) {
if (e.Row == null && grid.Columns[nameof(Invoice.Status)].GroupIndex == 0) {
var childRow = grid.FindRowByValue(grid.Columns[nameof(Invoice.Status)], InvoiceStatus.Invalidated);
var groupRow = grid.GetParentRowHandle(childRow);
grid.ExpandGroupRow(groupRow);
}
}
void OnGroupRowExpanding(object sender, RowAllowEventArgs e) {
if (e.Row != null && grid.GetGroupRowValue(e.RowHandle).Equals(InvoiceStatus.Delivered))
e.Allow = false;
}
void OnGroupRowExpanded(object sender, RowEventArgs e) {
if (e.Row == null && grid.Columns[nameof(Invoice.Status)].GroupIndex == 0) {
var childRow = grid.FindRowByValue(grid.Columns[nameof(Invoice.Status)], InvoiceStatus.Delivered);
var groupRow = grid.GetParentRowHandle(childRow);
grid.CollapseGroupRow(groupRow);
}
}
}
public class GroupRowTemplateSelector : DataTemplateSelector {
public DataTemplate RedRowTemplate { get; set; }
public DataTemplate GreenRowTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container) {
GridGroupValueData data = item as GridGroupValueData;
if (data.Text == nameof(InvoiceStatus.Invalidated))
return RedRowTemplate;
if (data.Text == nameof(InvoiceStatus.Delivered))
return GreenRowTemplate;
return base.SelectTemplate(item, container);
}
}
}