Meeting.Demo/Demo.Common/Converters/AspectRatioConverter.cs

40 lines
1.3 KiB
C#

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 Demo.Common.Converters
{
public class AspectRatioConverter : IMultiValueConverter
{
private readonly double ratio = 1.777;
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length == 2 && values[0] is double height && values[1] is double maxWidth)
{
Console.WriteLine($@"height {height} maxWidth {maxWidth}");
var controlWidth = height * ratio;
return controlWidth > maxWidth ? maxWidth : controlWidth;
}
//else if (values.Length == 4 && values[0] is double stackHeight
// && values[1] is double stackWidth && values[2] is int userPageSize
// && values[3] is Thickness margin)
//{
// var controlWidth = stackHeight * ratio;
//}
return 0;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}