40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using Avalonia.Data.Converters;
|
|
using Plugin.Cowain.Wcs.ViewModels;
|
|
using System.Globalization;
|
|
|
|
namespace Plugin.Cowain.Wcs.Converters;
|
|
|
|
public class CellPosToCanvansPosConverter : IValueConverter
|
|
{
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is int cellPosition)
|
|
{
|
|
double cellSize = 0;
|
|
if (parameter is double d)
|
|
{
|
|
cellSize = d;
|
|
}
|
|
else if (parameter is int i)
|
|
{
|
|
cellSize = i;
|
|
}
|
|
else if (parameter != null && double.TryParse(parameter.ToString(), out double parsed))
|
|
{
|
|
cellSize = parsed;
|
|
}
|
|
if (cellSize > 0)
|
|
{
|
|
return (double)cellPosition * cellSize;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|