Dreamine.UI.Wpf 1.0.1
Dreamine.UI.Wpf 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
NumberClampConverter.cs
이 파일의 문서화 페이지로 가기
1using System.Globalization;
2using System.Windows.Data;
3
5
14public class NumberClampConverter : IValueConverter
15{
80 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
81 {
82 if (value is IComparable comparableValue)
83 {
84 int? min = null;
85 int? max = null;
86
87 if (parameter is string str)
88 {
89 var parts = str.Split(';');
90 if (parts.Length > 0 && int.TryParse(parts[0], out int minVal))
91 min = minVal;
92 if (parts.Length > 1 && int.TryParse(parts[1], out int maxVal))
93 max = maxVal;
94 }
95
96 var numeric = System.Convert.ToInt32(value);
97
98 if (min.HasValue && numeric < min.Value)
99 return min.Value;
100
101 if (max.HasValue && numeric > max.Value)
102 return max.Value;
103
104 return numeric;
105 }
106 return value;
107 }
108
157 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
158 => Binding.DoNothing;
159}
object Convert(object value, Type targetType, object parameter, CultureInfo culture)
object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)