using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
namespace XP.ImageProcessing.RoiControl
{
///
/// 将Point列表转换为PointCollection,支持ObservableCollection变化通知
///
public class PointListToPointCollectionConverter : IValueConverter
{
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is List pointList)
{
return new PointCollection(pointList);
}
else if (value is ObservableCollection observablePoints)
{
var pointCollection = new PointCollection(observablePoints);
return pointCollection;
}
else if (value is IEnumerable enumerable)
{
return new PointCollection(enumerable);
}
return new PointCollection();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is PointCollection pointCollection)
{
var list = new ObservableCollection();
foreach (Point p in pointCollection)
{
list.Add(p);
}
return list;
}
return new ObservableCollection();
}
}
///
/// 索引转换为位置标�?
///
public class IndexToPositionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is int index)
{
return (index + 1).ToString();
}
return "0";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}