164 lines
5.2 KiB
C#
164 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
using UCalc.Models;
|
|
|
|
namespace UCalc.Controls
|
|
{
|
|
public class ErrorsToVisibilityConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return (((ICollection<string>) value)?.Count ?? 0) == 0 ? Visibility.Collapsed : Visibility.Visible;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
|
|
public class ErrorsToInVisibilityConverter : IValueConverter
|
|
{
|
|
private readonly ErrorsToVisibilityConverter _converter = new ErrorsToVisibilityConverter();
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var result = _converter.Convert(value, targetType, parameter, culture) as Visibility?;
|
|
return result == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
|
|
public class ErrorsToCountConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return ((ICollection<string>) value)?.Count ?? 0;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
|
|
public class ErrorsToToolTipConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var errors = (IReadOnlyList<string>) value;
|
|
|
|
return (errors?.Count ?? 0) == 0 ? null : string.Join("\n", errors);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
|
|
public class FlatToRentedConverter : IValueConverter
|
|
{
|
|
public TenantProperty Tenant { get; set; }
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return Tenant.RentedFlats.Contains((FlatProperty) value);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
|
|
public class FlatToAffectedConverter : IValueConverter
|
|
{
|
|
public CostProperty Cost { get; set; }
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return Cost.AffectedFlats.Contains((FlatProperty) value);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
|
|
public class EmptyMultiPropertyToVisibilityConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return value?.Equals(0) ?? false ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
|
|
public class DatePickerTextToDateTimeConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var dateTime = (DateTime?) value;
|
|
|
|
return dateTime == null ? "" : dateTime.Value.ToString(Constants.DateFormat);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var str = (string) value;
|
|
|
|
if (DateTime.TryParseExact(str, Constants.DateFormat, null, DateTimeStyles.None, out var d))
|
|
{
|
|
return d;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public class NameToTextConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var str = (string) value;
|
|
|
|
if (str == "")
|
|
{
|
|
return "(Unbenannt)";
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|
|
|
|
public class NegateConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return !(bool?) value;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return !(bool?) value;
|
|
}
|
|
}
|
|
} |