You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.0 KiB
75 lines
2.0 KiB
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Data;
|
|
|
|
namespace WPF.Converters
|
|
{
|
|
|
|
public class ToStringConverter : IValueConverter
|
|
{
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (parameter == null)
|
|
{
|
|
return value;
|
|
}
|
|
|
|
string key = string.Empty;
|
|
if (value == null)
|
|
{
|
|
key = "null";
|
|
}
|
|
else
|
|
{
|
|
key = value.ToString().ToLower();
|
|
}
|
|
string[] arr = parameter.ToString().Split('|');
|
|
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|
|
|
foreach (var str in arr)
|
|
{
|
|
string[] drr = str.Split(new string[] { "----" }, StringSplitOptions.None);
|
|
dic.Add(drr[0].ToLower(), drr[1]);
|
|
}
|
|
|
|
string defa = dic.FirstOrDefault().Value.ToString();
|
|
|
|
if (dic.ContainsKey(key))
|
|
{
|
|
if (dic[key] == "Collapsed")
|
|
return System.Windows.Visibility.Collapsed;
|
|
if (dic[key] == "Visible")
|
|
return System.Windows.Visibility.Visible;
|
|
|
|
return dic[key];
|
|
}
|
|
else if (defa == "Visible")
|
|
{
|
|
return System.Windows.Visibility.Collapsed;
|
|
}
|
|
else
|
|
if (defa == "Collapsed")
|
|
return System.Windows.Visibility.Visible;
|
|
else
|
|
if (defa.ToLower() == "false")
|
|
return true;
|
|
else if (defa.ToLower() == "true")
|
|
return false;
|
|
return defa;
|
|
}
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
string strValue = value.ToString();
|
|
return value;
|
|
}
|
|
|
|
}
|
|
}
|
|
|