Table of Contents

Class KeyGestureFormatInfo

Namespace
Avalonia.Input.Platform
Assembly
Avalonia.Base.dll

Provides platform specific formatting information for the KeyGesture class

public sealed class KeyGestureFormatInfo : IFormatProvider
Inheritance
KeyGestureFormatInfo
Implements
Inherited Members

Constructors

KeyGestureFormatInfo(IReadOnlyDictionary<Key, string>?, string, string, string, string)

Provides platform specific formatting information for the KeyGesture class

public KeyGestureFormatInfo(IReadOnlyDictionary<Key, string>? platformKeyOverrides = null, string meta = "Cmd", string ctrl = "Ctrl", string alt = "Alt", string shift = "Shift")

Parameters

platformKeyOverrides IReadOnlyDictionary<Key, string>

A dictionary of Key to String overrides for specific characters, for example Key.Left to "Left Arrow" or "←" on Mac. A null value is assumed to be the Invariant, so the included set of common overrides will be skipped if this is null. If only the common overrides are desired, pass an empty Dictionary instead.

meta string

The string to use for the Meta modifier, defaults to "Cmd"

ctrl string

The string to use for the Ctrl modifier, defaults to "Ctrl"

alt string

The string to use for the Alt modifier, defaults to "Alt"

shift string

The string to use for the Shift modifier, defaults to "Shift"

Properties

Alt

The string used to represent Alt on the appropriate platform. Defaults to "Alt".

public string Alt { get; }

Property Value

string

Ctrl

The string used to represent Ctrl on the appropriate platform. Defaults to "Ctrl".

public string Ctrl { get; }

Property Value

string

Invariant

The Invariant format. Only uses strings straight from the appropriate Enums.

public static KeyGestureFormatInfo Invariant { get; }

Property Value

KeyGestureFormatInfo

Meta

The string used to represent Meta on the appropriate platform. Defaults to "Cmd".

public string Meta { get; }

Property Value

string

Shift

The string used to represent Shift on the appropriate platform. Defaults to "Shift".

public string Shift { get; }

Property Value

string

Methods

FormatKey(Key)

Checks the platformKeyOverrides and s_commonKeyOverrides Dictionaries, in order, for the appropriate string to represent the given Key on this platform. NOTE: If platformKeyOverrides is null, this is assumed to be the Invariant and the Dictionaries are not checked. The plain Enum string is returned instead.

public string FormatKey(Key key)

Parameters

key Key

The Key to format.

Returns

string

The appropriate platform specific or common override if present, key.ToString() if not or this is the Invariant.

GetFormat(Type?)

public object? GetFormat(Type? formatType)

Parameters

formatType Type

Returns

object

GetInstance(IFormatProvider?)

Gets the most appropriate KeyGestureFormatInfo for the IFormatProvider requested. This will be, in order:

  1. The provided IFormatProvider as a KeyGestureFormatInfo
  2. The currently registered platform specific KeyGestureFormatInfo, if present.
  3. The Invariant otherwise.
public static KeyGestureFormatInfo GetInstance(IFormatProvider? formatProvider)

Parameters

formatProvider IFormatProvider

The IFormatProvider to get a KeyGestureFormatInfo for.

Returns

KeyGestureFormatInfo