68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 将Point列表转换为PointCollection,支持ObservableCollection变化通知
|
|
/// </summary>
|
|
public class PointListToPointCollectionConverter : IValueConverter
|
|
{
|
|
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is List<Point> pointList)
|
|
{
|
|
return new PointCollection(pointList);
|
|
}
|
|
else if (value is ObservableCollection<Point> observablePoints)
|
|
{
|
|
var pointCollection = new PointCollection(observablePoints);
|
|
return pointCollection;
|
|
}
|
|
else if (value is IEnumerable<Point> 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<Point>();
|
|
foreach (Point p in pointCollection)
|
|
{
|
|
list.Add(p);
|
|
}
|
|
return list;
|
|
}
|
|
return new ObservableCollection<Point>();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 索引转换为位置标签
|
|
/// </summary>
|
|
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();
|
|
}
|
|
}
|
|
} |