Skip to content
Back to skills

Displaying Slider Index

ASecurity

Displays 0-based collection indices as 1-based numbers in WPF Slider controls. Use when showing user-friendly slice/page numbers while maintaining 0-based internal indexing.

  • 666 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added February 8, 2026
development

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill displaying-slider-index --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Displaying Slider Index?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Displaying Slider Index
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-displaying-slider-index/badge)](https://www.skillsdirectory.com/skills/majiayu000-displaying-slider-index)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: displaying-slider-index
description: "Displays 0-based collection indices as 1-based numbers in WPF Slider controls. Use when showing user-friendly slice/page numbers while maintaining 0-based internal indexing."
---

# WPF Slider 0-based Index Display Pattern

## Problem Scenario

When displaying collection indices with a slider, **internally using 0-based index** but **displaying as 1-based to users** is a common requirement.

### Symptoms
- 120 images exist but displayed as "0 / 120" ~ "119 / 120"
- Users expect "1 / 120" ~ "120 / 120"
- Dragging slider to the end doesn't reach the last item

### Cause
- If slider's `Maximum` is set to `TotalCount`, it exceeds the valid range
- Displaying 0-based index directly confuses users

---

## Solution

### Add Display Properties to ViewModel

```csharp
public partial class ViewerViewModel : ObservableObject
{
    // Internal index (0-based)
    [NotifyPropertyChangedFor(nameof(SliceDisplayNumber))]
    [ObservableProperty] private int _currentSliceIndex;

    // Total count
    [NotifyPropertyChangedFor(nameof(MaxSliceIndex))]
    [ObservableProperty] private int _totalSliceCount;

    /// <summary>
    /// Slider Maximum value (0-based index maximum)
    /// </summary>
    public int MaxSliceIndex => Math.Max(0, TotalSliceCount - 1);

    /// <summary>
    /// User display number (1-based)
    /// </summary>
    public int SliceDisplayNumber => CurrentSliceIndex + 1;
}
```

### XAML Binding

```xml
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>

    <!-- Current number (1-based display) -->
    <TextBlock Grid.Column="0"
               Text="{Binding SliceDisplayNumber}" />

    <!-- Slider (0-based index, Maximum is Count-1) -->
    <Slider Grid.Column="1"
            Minimum="0"
            Maximum="{Binding MaxSliceIndex}"
            Value="{Binding CurrentSliceIndex}" />

    <!-- Total count -->
    <TextBlock Grid.Column="2"
               Text="{Binding TotalSliceCount}" />
</Grid>
```

---

## Key Points

| Property | Value Range | Purpose |
|----------|-------------|---------|
| `CurrentSliceIndex` | 0 ~ (Count-1) | Internal logic, Slider Value |
| `MaxSliceIndex` | Count-1 | Slider Maximum |
| `SliceDisplayNumber` | 1 ~ Count | User display |
| `TotalSliceCount` | Count | Total count display |

---

## Using NotifyPropertyChangedFor

The `[NotifyPropertyChangedFor]` attribute automatically raises `PropertyChanged` for computed properties when the source property changes.

```csharp
// When CurrentSliceIndex changes, SliceDisplayNumber also raises PropertyChanged
[NotifyPropertyChangedFor(nameof(SliceDisplayNumber))]
[ObservableProperty] private int _currentSliceIndex;

// When TotalSliceCount changes, MaxSliceIndex also raises PropertyChanged
[NotifyPropertyChangedFor(nameof(MaxSliceIndex))]
[ObservableProperty] private int _totalSliceCount;
```

---

## Application Examples

- Image viewer slice navigation (CT/MRI)
- Pagination (document viewer)
- Media player track list
- Gallery image index

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.