/
RowViewAlternation.cs
61 lines (52 loc) · 1.82 KB
/
RowViewAlternation.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
using System;
using DevZest.Data.Views;
using System.Windows.Media;
namespace DevZest.Data.Presenters
{
/// <summary>
/// Displays different background for <see cref="RowView"/> elements.
/// </summary>
public sealed class RowViewAlternation : RowViewBehavior
{
/// <summary>
/// Initializes a new instance of <see cref="RowViewAlternation"/>, with white for even and light gray for odd <see cref="RowView"/> elements.
/// </summary>
public RowViewAlternation()
: this(new Brush[] { Brushes.White, Brushes.LightGray })
{
}
/// <summary>
/// Initializes a new instance of <see cref="RowViewAlternation"/>, with specified background brushes.
/// </summary>
/// <param name="backgroundBrushes">The background brushes.</param>
public RowViewAlternation(Brush[] backgroundBrushes)
{
if (backgroundBrushes == null)
throw new ArgumentNullException(nameof(backgroundBrushes));
_backgroudnBrushes = backgroundBrushes;
}
private Brush[] _backgroudnBrushes;
/// <summary>
/// Gets the count of background brushes.
/// </summary>
public int AlternationCount
{
get { return _backgroudnBrushes.Length; }
}
/// <inheritdoc/>
protected internal override void Setup(RowView rowView)
{
}
/// <inheritdoc/>
protected internal override void Refresh(RowView rowView)
{
if (_backgroudnBrushes.Length == 0)
return;
rowView.Background = _backgroudnBrushes[rowView.RowPresenter.Index % AlternationCount];
}
/// <inheritdoc/>
protected internal override void Cleanup(RowView rowView)
{
}
}
}