In my database I have a 2 columns (Kind and Priority) that are of type int. I also have an enum with the values of Kind and Priority. But when I try to display them into a GridViewColumn, it shows the integers and not the enum values. Do I need a converter Here is the enums:
public enum Kind
{
None = 0,
Task = 1,
Assignment = 2,
Quiz = 3,
Test = 4,
Exam = 5,
Project = 6,
}
public enum Priority
{
None = 0,
Low = 1,
Medium = 2,
High = 3,
Top = 4,
}
And my XAML:
<GridViewColumn x:Name="PriorityColumn" Header="Priority" Width="60" DisplayMemberBinding="{Binding Path=Priority}" />
<GridViewColumn x:Name="KindColumn" Header="Kind" Width="60" DisplayMemberBinding="{Binding Path=Kind}" />
If the Priority and Kind properties are declared as type int, then yes, you will need a converter. WPF has no way of knowing that the properties declared as integer need to be interpreted as values from the enums.
If the Priority and Kind properties are declared as type Priority and Kind respectively, then it should just work: WPF displays enums by calling ToString() on them which will result in the name of the enum value.
For example:
(When populating a Job object you will of course need to cast the ints coming out of the database to Kind and Priority, or you stick with an int backing field and do the casting in the getter and setter. If you are using a good ORM then it should be able to take care of this for you.)