Created
July 4, 2017 08:02
-
-
Save jfversluis/d90ae351edf6e0139e986e315e6fa0d1 to your computer and use it in GitHub Desktop.
Implemented Convert method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Globalization; | |
using SampleValueConverters.Enums; | |
using Xamarin.Forms; | |
namespace SampleValueConverters.ValueConverters | |
{ | |
public class PlatformToColorConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
if (value == null) | |
return Color.Black; | |
if (!Enum.TryParse(value.ToString(), out Platform enumValue)) | |
return Color.Black; | |
switch (enumValue) | |
{ | |
case Platform.Playstation: | |
return Color.Purple; | |
case Platform.Wii: | |
return Color.Red; | |
case Platform.Xbox: | |
return Color.Green; | |
default: | |
return Color.Black; | |
} | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment