Commit 6c67770d authored by 潘栩锋's avatar 潘栩锋 🚴

添加 Item2NoConverter 列表item 转 编号,编号从1开始

parent 549e2ec5
......@@ -24,4 +24,5 @@
<conv:RatioConverter_TimeSpan x:Key="ratioconv_ts" />
<conv:Item2IndexConverter x:Key="i2iConv"/>
<conv:Item2NoConverter x:Key="i2noConv"/>
</ResourceDictionary>
\ No newline at end of file
......@@ -39,4 +39,37 @@ namespace FLY.ControlLibrary.Converter
throw new NotImplementedException();
}
}
/// <summary>
/// 列表转Number 从1开始
/// </summary>
[ValueConversion(typeof(object), typeof(int))]
public class Item2NoConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
int result = -1;
if (value != null)
{
var collectionViewSource = parameter as CollectionViewSource;
if (collectionViewSource != null)
{
var cv = (CollectionView)collectionViewSource.View;
//在 设计模式中, View为null, 所以下面必须判断
if (cv != null)
{
result = cv.IndexOf(value);
}
}
}
return result >= 0 ? result + 1 : System.Windows.DependencyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment