-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntToColorConverter.cs
46 lines (40 loc) · 1.36 KB
/
IntToColorConverter.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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Xamarin.Forms;
namespace PsApp
{
class IntToColorConverter : IValueConverter
{
public int Faction1Id { get; set; } = 1;
public Color Faction1Color { get; set; } = Color.FromRgb(68,15,98);
public int Faction2Id { get; set; } = 3;
public Color Faction3Color { get; set; } = Color.FromRgb(0, 75, 128);
public int Faction3Id { get; set; } = 2;
public Color Faction2Color { get; set; } = Color.FromRgb(158, 11, 15);
public Color DefaultFactionColor { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is int i)
{
if (i == Faction1Id)
return Faction1Color;
if (i == Faction2Id)
return Faction2Color;
if (i == Faction3Id)
return Faction3Color;
return DefaultFactionColor;
}
else
{
// cannot convert, return the given value as-is
return value;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
}