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.

40 lines
975 B

  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Data;
  4. using System.Windows.Markup;
  5. namespace BPA.UIControl.Converters
  6. {
  7. /// <summary>
  8. /// 克隆内容
  9. /// </summary>
  10. public class CloneConverter : IValueConverter
  11. {
  12. /// <inheritdoc/>
  13. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  14. {
  15. if (value == null)
  16. {
  17. return value;
  18. }
  19. try
  20. {
  21. string xaml = XamlWriter.Save(value);
  22. var cloneValue = XamlReader.Parse(xaml);
  23. return cloneValue;
  24. }
  25. catch (Exception)
  26. {
  27. return value;
  28. }
  29. }
  30. /// <inheritdoc/>
  31. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  32. {
  33. throw new NotImplementedException();
  34. }
  35. }
  36. }