0
点赞
收藏
分享

微信扫一扫

WPF ItemsControl 自动序号的实现

人间四月天i 2022-03-11 阅读 144
    /// <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>
举报

相关推荐

0 条评论