4 changed files with 165 additions and 61 deletions
@ -0,0 +1,68 @@ |
|||
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]); |
|||
} |
|||
|
|||
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 (dic.FirstOrDefault().Value.ToString() == "Visible") |
|||
{ |
|||
return System.Windows.Visibility.Collapsed; |
|||
} |
|||
else |
|||
if (dic.FirstOrDefault().Value.ToString() == "Collapsed") |
|||
return System.Windows.Visibility.Visible; |
|||
return value; |
|||
} |
|||
|
|||
|
|||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
|||
{ |
|||
string strValue = value.ToString(); |
|||
return value; |
|||
} |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue