/// <summary>
/// 0变成0+1 x变成x+1
/// </summary>
public class NumberConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return 0;
return System.Convert.ToInt32(value) + 1;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
<TextBlock HorizontalAlignment="Left" Foreground="#000000" FontWeight="Bold" VerticalAlignment="Center" Margin="2 0 0 0">
<TextBlock.Text>
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ContentPresenter}}"
Path="(ItemsControl.AlternationIndex)" Converter="{StaticResource NumberConverter}" />
</TextBlock.Text>
</TextBlock>