Table of Contents

Class IndexToLetterConverter

Namespace
Tudormobile.OpenTrivia.UI.Converters
Assembly
Tudormobile.OpenTrivia.UI.dll

Converts a zero-based numeric index to its corresponding uppercase letter representation.

public class IndexToLetterConverter : IValueConverter
Inheritance
IndexToLetterConverter
Implements
Inherited Members

Remarks

This converter is useful for displaying answer choices in multiple-choice questions where answers are traditionally labeled A, B, C, D, etc. The converter supports indices 0-25, mapping them to letters A-Z. Values outside this range return an empty string.

Examples:

  • 0 → "A"
  • 1 → "B"
  • 2 → "C"
  • 25 → "Z"
  • 26 or higher → ""
  • -1 or lower → ""

Constructors

IndexToLetterConverter()

public IndexToLetterConverter()

Methods

Convert(object?, Type, object?, CultureInfo)

Converts a zero-based integer index to its corresponding uppercase letter.

public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)

Parameters

value object

The zero-based index to convert. Must be an integer between 0 and 25.

targetType Type

The type of the binding target property. This parameter is not used.

parameter object

An optional parameter. This parameter is not used.

culture CultureInfo

The culture to use in the converter. This parameter is not used.

Returns

object

A string containing a single uppercase letter (A-Z) if the index is valid (0-25); otherwise, returns an empty string.

Examples

var converter = new IndexToLetterConverter();
var result = converter.Convert(0, typeof(string), null, CultureInfo.InvariantCulture);
// result = "A"

ConvertBack(object?, Type, object?, CultureInfo)

Converts a letter back to its zero-based index. This operation is not supported.

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)

Parameters

value object

The value to convert back.

targetType Type

The type to convert to.

parameter object

An optional parameter.

culture CultureInfo

The culture to use in the converter.

Returns

object

This method always throws NotImplementedException.

Exceptions

NotImplementedException

This converter is designed for one-way binding only. Reverse conversion is not supported.