I want to extend Shapes.Rectangle WPF built-in class with some additional proprietary properties. I can do this in 3 different ways:
- Declare my own wrapper class and have WPF Rectangle as one of its members.
- Declare my own struct/class with my proprietary properties and put it in Rectangle.Tag field.
- 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! :)
精彩评论