123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using System.Globalization;
- using System.Windows.Data;
- using System.Windows.Markup;
- using Brushes = System.Windows.Media.Brushes;
- namespace Flyinsono.Client.Test.Extensions
- {
- public class LogLevelToColorConvertExtension : MarkupExtension, IValueConverter
- {
- [ThreadStatic]
- private static LogLevelToColorConvertExtension _converter;
- public override object ProvideValue(IServiceProvider serviceProvider)
- {
- return _converter ?? (_converter = new LogLevelToColorConvertExtension());
- }
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value != null)
- {
- if (Enum.TryParse(value.ToString(), out LogLevel level))
- {
- switch (level)
- {
- case LogLevel.Info:
- return Brushes.Blue;
- case LogLevel.Warn:
- return Brushes.Goldenrod;
- case LogLevel.Error:
- return Brushes.Red;
- }
- }
- }
- return Brushes.Black;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- }
|