first edit
This commit is contained in:
31
XLIMS.MVVM/Converters/BoolConverter.cs
Normal file
31
XLIMS.MVVM/Converters/BoolConverter.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
using System.Globalization;
|
||||
|
||||
namespace XLIMS.MVVM.Converters
|
||||
{
|
||||
[ValueConversion(typeof(Boolean), typeof(String))]
|
||||
public class BoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
Boolean data = (Boolean)value;
|
||||
return data;
|
||||
}
|
||||
catch { return value; }
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
string strValue = value.ToString();
|
||||
Boolean resultData;
|
||||
if (Boolean.TryParse(strValue, out resultData))
|
||||
{
|
||||
return resultData;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
XLIMS.MVVM/Converters/CompositeCollectionConverter.cs
Normal file
35
XLIMS.MVVM/Converters/CompositeCollectionConverter.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace XLIMS.MVVM.Converters
|
||||
{
|
||||
[ValueConversion(typeof(object),typeof(CompositeCollection))]
|
||||
public class CompositeCollectionConverter : IMultiValueConverter
|
||||
{
|
||||
|
||||
public object Convert(object[] values
|
||||
, Type targetType
|
||||
, object parameter
|
||||
, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var res = new CompositeCollection();
|
||||
foreach (var item in values)
|
||||
if (item is IEnumerable)
|
||||
res.Add(new CollectionContainer()
|
||||
{
|
||||
Collection = item as IEnumerable
|
||||
});
|
||||
else res.Add(item);
|
||||
return res;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value
|
||||
, Type[] targetTypes
|
||||
, object parameter
|
||||
, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
25
XLIMS.MVVM/Converters/DateConverter.cs
Normal file
25
XLIMS.MVVM/Converters/DateConverter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
using System.Globalization;
|
||||
|
||||
namespace XLIMS.MVVM.Converters
|
||||
{
|
||||
[ValueConversion(typeof(DateTime), typeof(string))]
|
||||
public class DateConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is DateTime)) return string.Empty;
|
||||
DateTime test = (DateTime)value;
|
||||
string date = test.ToString();
|
||||
return (date);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var strValue = value.ToString();
|
||||
DateTime resultDateTime;
|
||||
return DateTime.TryParse(strValue, out resultDateTime) ? resultDateTime : value;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
XLIMS.MVVM/Converters/ImageConverter.cs
Normal file
34
XLIMS.MVVM/Converters/ImageConverter.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Drawing;
|
||||
|
||||
namespace XLIMS.MVVM.Converters
|
||||
{
|
||||
[ValueConversion(typeof(Byte[]), typeof(Image))]
|
||||
public class ImageConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ms = new MemoryStream((byte[])value);
|
||||
var returnImage = Image.FromStream(ms);
|
||||
return returnImage;
|
||||
}
|
||||
catch { return value; }
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
//MemoryStream ms = new MemoryStream();
|
||||
//value.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
XLIMS.MVVM/Converters/VisibilityConverter.cs
Normal file
32
XLIMS.MVVM/Converters/VisibilityConverter.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
|
||||
namespace XLIMS.MVVM.Converters
|
||||
{
|
||||
[ValueConversion(typeof(string), typeof(Visibility))]
|
||||
public class VisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
return Visibility.Visible;
|
||||
//string s = value.ToString();
|
||||
//object s1 = value;
|
||||
//if (s1 is decimal)
|
||||
// if ((decimal.Parse(s1.ToString())) == 0) return Visibility.Collapsed;
|
||||
//if (s1 is bool)
|
||||
// if ((bool.Parse(s1.ToString())) == false) return Visibility.Collapsed;
|
||||
//if (string.IsNullOrEmpty(s)) return Visibility.Collapsed;
|
||||
}
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user