Skip to content

Enumerate is a markup extension and a value converter which allow to bind to Enum properties in XAML.

License

Notifications You must be signed in to change notification settings

YohDeadfall/Enumerate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enumerate

Enumerate is a markup extension and a value converter which allow to bind to Enum properties in XAML. It also supports other types for which TypeConverter.GetStandardValues() returns a collection of standard values.

Features

  1. Providing values of an Enum as is.
  2. Providing values of an Enum from DescriptionAttributes.

Usage:

public enum ViewModelStatus
{
    [Description("Offen")]
    Open,
    [Description("Geschlossen")]
    Closed,
    [Description("In Arbeit")]
    InProgress
}

public class ViewModel : INotifyPropertyChanged
{
    public ViewModelStatus Status { get; set; }
}
<ComboBox ItemsSource="{e:Enumerate {x:Type local:ViewModelStatus}, Converter={StaticResource EnumToStringConverter}}"
          SelectedItem="{Binding Status, Converter={StaticResource EnumToStringConverter}}" />
<!-- ItemsSource will contain Offen, Geschlossen and In Arbeit -->

Localization

Specify an ResourceManager in the Description property and apply this attribute to an Enum values.

public class LocalizedDescriptionAttribute : DescriptionAttribute
{
    #region Fields

    private string resourceName;

    #endregion

    #region Constructors

    public LocalizedDescriptionAttribute(string resourceName)
    {
        this.resourceName = resourceName;
    }

    #endregion

    #region DescriptionAttribute Members

    public override string Description
    {
        get { return Resources.ResourceManager.GetString(resourceName); }
    }

    #endregion

    #region Properties

    public string ResourceName
    {
        get { return resourceName; }
    }

    #endregion
}

About

Enumerate is a markup extension and a value converter which allow to bind to Enum properties in XAML.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages