开发者

please help with best approach for extension of WPF built-in class

I want to extend Shapes.Rectangle WPF built-in class with some additional proprietary properties. I can do this in 3 different ways:

  1. Declare my own wrapper class and have WPF Rectangle as one of its members.
  2. Declare my own struct/class with my proprietary properties and put it in Rectangle.Tag field.
  3. Declare WPF dependency property for each of my proprietary properties and use Rectangle.SetValue() & Rectangle.GetValue() methods.

What is the best approach from performance point of view (speed, memory consumption), giving that at every moment only part of my proprietary properties wil开发者_运维问答l have meaningful value ?

Thanks.


You can Create a Behavior that extends Behavior.

That's the best and easiest way (and Blend friendly) to add behavior to existing elements. It's part of WPF4 now, and you can use it after u add a reference to System.Windows.Interactivity.


Are you going to be using your "sort of" derived Rectangle everywhere, or is it going to sometimes be a Rectangle and sometimes yours?

If you're going to be using some of your properties every single time, I would say you should create a wrapper class and just keep it as lightweight as possible. That'll keep your code as clean as possible. I don't think the performance will be an issue unless you're doing thousands of these. And if you are, then you might have other issues! :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜