I have come across a very interesting issue.
Suppose you have the following XAML page content in a UWP app:
<ContentControl Content="{x:Bind ApplicationDataLocalityEnum}" />
<ContentControl Content="{x:Bind FontStyleEnum}" />
And in the code-behind of the page contains the following properties:
public ApplicationDataLocality ApplicationDataLocalityEnum { get; } =
ApplicationDataLocality.Local;
public FontStyle FontStyleEnum { get; } =
FontStyle.Normal;
Expected result would be, that the app would display "Local" and "Normal".
Actual result is however the following:
What is the reason behind this? I am very curious about it, but even though I have tried digging into debugger values for a long time, it never revealed anything that could cause this.
You can play around with my sample project on GitHub.
Should you look into the source of
FontStyle
(just hit F12) you will find it is inWindows.Foundation.UniversalApiContract.winmd
. This is not a .NET assembly, but a native assembly projected into .NET. MSDN for IReference says:So why doesn't it work?
The heart of the answer is, this is not a .NET type and does not behave like a .NET type. Meaning
ToString()
is not natively implemented as if it is anenum
but acts instead likeGetType().ToString()
, which explains the output you are seeing.Why don't they make it work?
To correct this on the platform side, the type would need a mechanism to differentiate between numerations, structures and delegates. In the case of structures and delegates, you would expect
ToString()
to returnGetType().ToString()
and not a name value; so this generic behavior is the most common choice across the options.