| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
- // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Data;
- using System.Globalization;
- using System.Windows;
- using System.Collections;
- namespace ICSharpCode.WpfDesign.Designer.Converters
- {
- public class IntFromEnumConverter : IValueConverter
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
- public static readonly IntFromEnumConverter Instance = new IntFromEnumConverter();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return (int)value;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return Enum.ToObject(targetType, (int)value);
- }
- }
- public class HiddenWhenFalse : IValueConverter
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
- public static readonly HiddenWhenFalse Instance = new HiddenWhenFalse();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return (bool)value ? Visibility.Visible : Visibility.Hidden;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- public class CollapsedWhenFalse : IValueConverter
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
- public static readonly CollapsedWhenFalse Instance = new CollapsedWhenFalse();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return (bool)value ? Visibility.Visible : Visibility.Collapsed;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- public class LevelConverter : IValueConverter
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
- public static readonly LevelConverter Instance = new LevelConverter();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return new Thickness(2 + 14 * (int)value, 0, 0, 0);
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- public class CollapsedWhenZero : IValueConverter
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
- public static readonly CollapsedWhenZero Instance = new CollapsedWhenZero();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value == null || (int)value == 0) {
- return Visibility.Collapsed;
- }
- return Visibility.Visible;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- public class FalseWhenNull : IValueConverter
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
- public static readonly FalseWhenNull Instance = new FalseWhenNull();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return value != null;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- public class BoldWhenTrue : IValueConverter
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
- public static readonly BoldWhenTrue Instance = new BoldWhenTrue();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return (bool)value ? FontWeights.Bold : FontWeights.Normal;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- // Boxed int throw exception without converter (wpf bug?)
- public class DummyConverter : IValueConverter
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
- public static readonly DummyConverter Instance = new DummyConverter();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return value;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return value;
- }
- }
-
- public class FormatDoubleConverter : IValueConverter
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
- public static readonly FormatDoubleConverter Instance=new FormatDoubleConverter();
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return Math.Round((double)value);
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- }
|