1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- 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<bool, string> m_DicItems;
- public BoolToStringConverter(Dictionary<bool, string> dicItems)
- {
- m_DicItems = dicItems ?? new Dictionary<bool, string>();
- }
- 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;
- }
- }
- }
|