1

I have a textbox and is bound to a property.

public SapLanguage Language
{
    get { return _language; }
    set
    {
        _language = value;
        RaisePropertyChanged();
    }
}

The SapLanguage is type enum:

public enum SapLanguage
{
    DE,
    EN,
    FR,
    IT
}

The WPF looks like as follow:

<TextBox Grid.Row="3" Grid.Column="1" Margin="10,10,10,10" FontSize="26" FontWeight="Bold"
                     CharacterCasing="Upper"
                     HorizontalAlignment="Left" VerticalContentAlignment="Center" MaxLength="2" Width="60"
                     HorizontalContentAlignment="Center" Text="{Binding Language, StringFormat={} }">
</TextBox>

When I type a value in the textbox, that does not exist. It shows me an error:

enter image description here

How can I store the error message into a variable?

softshipper
  • 32,463
  • 51
  • 192
  • 400

1 Answers1

2

For binding an enum to a TextBox you would need a converter class that implements the IValueConverter interface.

For displaying an enum, i wold prefer using a ComboBox instead, like this: https://stackoverflow.com/a/6145957/5764665

Community
  • 1
  • 1
Franz Wimmer
  • 1,477
  • 3
  • 20
  • 38