开发者

Is there any way to instantiate a 'Type' in Silverlight XAML?

I开发者_StackOverflow社区t's well known that Silverlight lacks the very compelling x:Type MarkupExtension (MarkupExtension is not supported in Silverlight at all). Is there any dynamic workaround for it?

What about enums (x:Static)?

My need is to have a CommandParameter set to a Type or Enum value, neither of these are supported in Silverlight!


This generally has to be done in the code-behind. Even if you build a custom object that exposes a property of type Type, it will not get properly "converted" when set via XAML.

This extra limitation prevents you from creating things like a custom EnumValueProvider, which exposes a Type property and updates a Values properties with the enum values from the specified enumeration type. Having a class like this would allow you to bind a ComboBox or ListBox to a list of enumeration values completely in XAML.

You can create a custom TypeConverter for the above Type property, to somewhat work around this issue. But you don't get the xmlns resolution that you'd expect. But depending on your situation, this may be good enough.

Here is another example, that exposes "known" types via properties, which you can then bind to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜