I have a UserControl that I built that has properties which are defined in the xaml like this:
<Repeater:JointScoringGrid x:Name="PIPLeftErosionsRepeater"
TabName="PIP"
Header="Erosion"
ControlNamePrefix="Left"
ScoringType="Erosions">
Then, in my code behind I have logic centered around the ScoringType. Currently I’m checking which ScoringType the Grid is by evaluating the string (i.e. ScoringType.ToUpper().Equals("EROSIONS") ) which works, but it’s not as clean as I’d like it to be. What I would rather do is use an enumeration, but use the name in the xaml rather than the numeric value (e.g. I want to use something like ScoringType="Enum.Erosions" instead of ScoringType="0" to make the xaml more readable). Can this be accomplished?
Just change the type of the property to the enum type, it should automatically parse the string to the enum value. (e.g.
HorizontalAlignment="Stretch"works, just an enum property)