开发者

Silverlight 4, data binding and dynamic objects

开发者 https://www.devze.com 2023-03-08 18:57 出处:网络
I have a control which uses the old-style data biding via *MemberPath properties. However, my situation requires the usage of a DynamicObject. When you get the type of that dynamic object开发者_Python

I have a control which uses the old-style data biding via *MemberPath properties. However, my situation requires the usage of a DynamicObject. When you get the type of that dynamic object开发者_Python百科 and call GetProperty(..) it returns null (because the object itself does not contain such a property - it is a dynamic one). So.. how can I solve this issue? How can I bind an object with dynamic properties having that the view uses that old-style data binding approach?


You're somewhat out of luck in Silverlight 4. Silverlight 5 (in beta) has the ICustomTypeProvider interface to allow binding to dynamic properties, but Silverlight 4 doesn't have this. Until Silverlight 5 is released, you have two options:

1) Write a value converter to get the value from the object.

OR

2) Have an indexer on your object that when passed a "property" name, returns the corresponding value. You can then extract the value like so:

Binding="{Binding [PropertyName]}"

Option 2 is the best option IMO.

0

精彩评论

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