Dreamine.UI.Wpf 1.0.1
Dreamine.UI.Wpf 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
BooleanToBrushConverter.cs
이 파일의 문서화 페이지로 가기
1using System.Globalization;
2using System.Windows;
3using System.Windows.Data;
4using System.Windows.Media;
5
7{
16 public class BooleanToBrushConverter : IValueConverter
17 {
26 public Brush OnBrush { get; set; } = Brushes.Lime;
27
36 public Brush OffBrush { get; set; } = Brushes.Gray;
37
86 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
87 {
88 bool flag = false;
89 if (value is bool b)
90 flag = b;
91 return flag ? OnBrush : OffBrush;
92 }
93
142 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
143 => Binding.DoNothing;
144 }
145
154 public class BrushOrUnsetConverter : IValueConverter
155 {
164 public Brush? OnBrush { get; set; } = new BrushConverter().ConvertFromString("#A2DED0") as Brush ?? Brushes.Transparent;
165
174 public Brush? OffBrush { get; set; } = null;
175
184 public bool UseUnsetWhenFalse { get; set; } = true;
185
234 public object Convert(object v, Type t, object p, CultureInfo c)
235 {
236 bool isOn = v is bool b && b;
237
238 if (isOn)
239 return OnBrush ?? DependencyProperty.UnsetValue;
240
241 if (!UseUnsetWhenFalse && OffBrush != null)
242 return OffBrush;
243
244 // 기본색(스타일/템플릿 기본값)로 복귀
245 return DependencyProperty.UnsetValue;
246 }
247
296 public object ConvertBack(object v, Type t, object p, CultureInfo c) => Binding.DoNothing;
297 }
298}
object Convert(object value, Type targetType, object parameter, CultureInfo culture)
object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
object Convert(object v, Type t, object p, CultureInfo c)
object ConvertBack(object v, Type t, object p, CultureInfo c)