VS XAML 设计器如何知道自动填充某些值的内容?
在上述按钮的 XAML 定义中,FontStyle
属性设置为斜体。当我点击 =
符号时,设计者能够以某种方式填充一个列表供我选择。这是如何实现的?
在回答之前,请考虑一下 FontStyle
属性的类型是 FontStyle
(这是一个结构体)。它不是一个枚举,这对于 VS 在设计时列出来是微不足道的,那么如何选择显示有效的选项列表呢?还有一个完全独立的 FontStyles
类,其中包含三个静态字段:Italic
、Normal
和 Oblique
,它们只是VS 在下拉列表中提供了三个项目。 FontStyle
结构和 FontStyles
类之间是否在幕后进行了一些映射,因为我在对象浏览器和 .NET Reflector 中查看了很多地方,并且无法确定任何事情。
谢谢!!
我需要知道!*
*不是真的,但如果能知道那就太好了:)
<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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
XAML 语言服务使用类型转换器的 GetStandardValues() 来确定在类型的下拉列表中显示的内容。例如,这与属性网格所做的事情相同。
不幸的是,框架提供的类型转换器并不总是实现 GetStandardValues(),因此设计者通常会为许多此类类型提供内部替换。属性网格和 XAMl 语言服务使用这些内部替换。
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.
我没有答案,但一件有趣的事情是有一个内部 FontStyle 枚举。 MS.Internal.Text.TextInterface.Font 样式定义为
这可能是向设计者公开用于智能感知的样式。
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
This might be what is being exposed to the designer to use for intellisense.