feat: commit content which I don't know when I create them
This commit is contained in:
@@ -4,20 +4,20 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace BallanceTasEditor.Converters {
|
||||
public class GenericConverter<TIn, TOut> : IValueConverter {
|
||||
|
||||
private readonly Func<TIn, TOut> converter;
|
||||
|
||||
public GenericConverter(Func<TIn, TOut> converter) { this.converter = converter; }
|
||||
[ValueConversion(typeof(int), typeof(string))]
|
||||
public class FpsConverter : IValueConverter {
|
||||
public static FpsConverter Instance = new FpsConverter();
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is TIn t) {
|
||||
return converter(t);
|
||||
if (value is int tv) {
|
||||
if (tv <= 0) return DependencyProperty.UnsetValue;
|
||||
else return Utils.FpsConverter.ToDelta(tv).ToString();
|
||||
} else {
|
||||
return Binding.DoNothing;
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,25 @@ namespace BallanceTasEditor.Converters {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConverterWarehouse {
|
||||
public static readonly GenericConverter<int, string> FpsConverter =
|
||||
new GenericConverter<int, string>((v) => Utils.FpsConverter.ToDelta(v).ToString());
|
||||
/// <summary>
|
||||
/// 将IsEnable转换为Visibility。
|
||||
/// </summary>
|
||||
[ValueConversion(typeof(bool), typeof(Visibility))]
|
||||
public class VisibilityConverter : IValueConverter {
|
||||
public static VisibilityConverter Instance = new VisibilityConverter();
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is bool bv) {
|
||||
if (bv) return Visibility.Visible;
|
||||
else return Visibility.Collapsed;
|
||||
} else {
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
35
BallanceTasEditor/Converters/StringifyConverter.cs
Normal file
35
BallanceTasEditor/Converters/StringifyConverter.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace BallanceTasEditor.Converters {
|
||||
|
||||
[ValueConversion(typeof(int?), typeof(string))]
|
||||
public class StringifyIntegerConverter : IValueConverter {
|
||||
public static StringifyIntegerConverter Instance = new StringifyIntegerConverter();
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is null) {
|
||||
return "";
|
||||
} else if (value is int iv) {
|
||||
return iv.ToString();
|
||||
} else {
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is string s) {
|
||||
if (int.TryParse(s, out int iv)) return iv;
|
||||
else return null;
|
||||
} else {
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user