mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
GameData and Converter Changes (#6)
This commit is contained in:
parent
b63ceae2aa
commit
671096a758
4 changed files with 79 additions and 5 deletions
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace ServerManagerTool.Common.Converters
|
||||
{
|
||||
public class FloatToStringConverter : IValueConverter
|
||||
{
|
||||
public const string DEFAULT_CULTURE_CODE = "en-US";
|
||||
public const int MIN_VALUE = 0;
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var floatValue = System.Convert.ToSingle(value);
|
||||
floatValue = Math.Max(MIN_VALUE, floatValue);
|
||||
|
||||
return ((float)floatValue).ToString("0.000000####", CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE));
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var floatValue = System.Convert.ToSingle(value);
|
||||
floatValue = Math.Max(MIN_VALUE, floatValue);
|
||||
|
||||
return floatValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace ServerManagerTool.Common.Converters
|
||||
{
|
||||
public class IntToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double scaledValue = System.Convert.ToInt32(value);
|
||||
return scaledValue == 0 ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException("IntToVisibilityConverter is a OneWay converter.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace ServerManagerTool.Common.Converters
|
||||
{
|
||||
public class InvertIntToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double scaledValue = System.Convert.ToInt32(value);
|
||||
return scaledValue == 0 ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException("InvertIntToVisibilityConverter is a OneWay converter.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue