1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Globalization;
using System.Windows.Data;
 
namespace HMI.Core
{
    public class WidthSizeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            /// "{size},{基准值},{最小值},{最大值}"
            if (parameter == null) return 15;
 
            string[] ps = parameter.ToString().Split(',');
            double size = double.Parse(ps[0]);
            double baseSize = double.Parse(ps[1]);
            double min = -1, max = -1;
 
            if (ps.Length >= 3)
            {
                min = double.Parse(ps[2]);
            }
            if (ps.Length >= 4)
            {
                max = double.Parse(ps[3]);
            }
 
            if (value is double width)
            {
                double res = CountFontSize(size, width, baseSize);
                res = min > 0 && res < min ? min : res;
                res = max > 0 && res > max ? max : res;
                return res;
            }
            return 15;
        }
 
        public static double CountFontSize(double size, double limit, double baseSize)
        {
            return size * limit / baseSize;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
 
    public class HeightSizeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter == null) return 15;
 
            string[] ps = parameter.ToString().Split(',');
            int size = int.Parse(ps[0]);
            int baseSize = int.Parse(ps[1]);
            double min = -1, max = -1;
 
            if (ps.Length >= 3)
            {
                min = double.Parse(ps[2]);
            }
            if (ps.Length >= 4)
            {
                max = double.Parse(ps[3]);
            }
            if (value is double height)
            {
                double res = CountFontSize(size, height, baseSize);
                res = min > 0 && res < min ? min : res;
                res = max > 0 && res > max ? max : res;
                return res;
            }
            return 15;
        }
 
        public static double CountFontSize(double size, double limit, double baseSize)
        {
            return size * limit / baseSize;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}