mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 08:26:30 +00:00
33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace Azaion.Dataset.Controls
|
|
{
|
|
public class ProportionToWidthConverter : IMultiValueConverter
|
|
{
|
|
private const double MinPixelBarWidth = 2.0;
|
|
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (values == null || values.Length < 2 ||
|
|
!(values[0] is double proportion) ||
|
|
!(values[1] is double containerActualWidth))
|
|
return MinPixelBarWidth; // Default or fallback width
|
|
|
|
if (containerActualWidth <= 0 || !double.IsFinite(containerActualWidth) || double.IsNaN(containerActualWidth))
|
|
return MinPixelBarWidth; // Container not ready or invalid
|
|
|
|
double calculatedWidth = proportion * containerActualWidth;
|
|
|
|
if (proportion >= 0 && calculatedWidth < MinPixelBarWidth)
|
|
return MinPixelBarWidth;
|
|
|
|
return Math.Max(0, calculatedWidth); // Ensure width is not negative
|
|
}
|
|
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |