views:

47

answers:

2

<Button Name="MyButton" Content="Test" FontStyle="Italic" />

In the above XAML definition of a button, the FontStyle property is set to Italic. The designer is somehow able to populate a list for me to choose from when I hit the = sign. How is this achieved?

Before you answer, consider that the FontStyle property is, appropriately enough, of type FontStyle (which is a struct). It's not an enumeration, which would be trivial for VS to list out at design time, so how are the valid list of options chosen to be displayed? There is also a completely separate FontStyles class which contains three static fields, Italic, Normal, and Oblique which just so happen to be the three items VS provides in the drop down list. Is there some mapping going on behind the scenes between the FontStyle struct and FontStyles class, because I've looked in many places in both the object browser and in .NET Reflector and couldn't determine anything from either.

Thanks!!

I NEED to know!*

*Not really, but it would be nice to :)

A: 

I do not have the answer, but one interesting thing is that there is an internal FontStyle enum. MS.Internal.Text.TextInterface.Font style which is defined as

internal enum FontStyle
{
    Normal,
    Oblique,
    Italic
}

This might be what is being exposed to the designer to use for intellisense.

Chris Taylor
+1  A: 

The XAML language service uses the type converter's GetStandardValues() to determine what to show in the drop-down list for a type. This is the same thing the property grid does, for example.

Unfortunately, the framework provided type converter doesn't always implement GetStandardValues() so the designer will often provide internal replacements for many such types. The property grid and the XAMl language service use these internal replacements.

chuckj
Interesting, that makes some sense. Thanks for the answer!
Pwninstein