using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; namespace FWindSoft.Wpf.Converter { public class BoolToStringConverter : IValueConverter { private Dictionary m_DicItems; public BoolToStringConverter(Dictionary dicItems) { m_DicItems = dicItems ?? new Dictionary(); } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value.GetType() != typeof(bool)) return string.Empty; string result = string.Empty; if (m_DicItems.TryGetValue((bool) value, out result)) { return result; } return value.ToString(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (targetType != typeof(bool)) return false; foreach (var mDicItem in m_DicItems) { if (mDicItem.Value == value.ToString()) return mDicItem.Key; } return false; } } }