ItemsToStringConverter.cs 975 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Data;
  9. namespace FWindSoft.Wpf
  10. {
  11. [ValueConversion(typeof(IEnumerable),typeof(string))]
  12. public class ItemsToStringConverter : IValueConverter
  13. {
  14. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  15. {
  16. var items = value as IEnumerable;
  17. if (items == null)
  18. return string.Empty;
  19. List<object> tempItems = new List<object>();
  20. foreach (var item in items)
  21. {
  22. tempItems.Add(item);
  23. }
  24. return string.Join(",", tempItems);
  25. }
  26. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  27. {
  28. throw new NotImplementedException();
  29. }
  30. }
  31. }