Creating a bindable Point in C# WPF

后端 未结 4 2078
执念已碎
执念已碎 2021-02-15 23:51

I know multiple inheritence is out, but is there a way to create a wrapper for System.Windows.Point that can inherit from it but still implement bindable dependency properties?<

4条回答
  •  盖世英雄少女心
    2021-02-16 00:18

    You may have to reimplement all the classes (Point, Polygon, Line etc.) from scratch, because Point is a structure, therefore it doesn't support inheritance (which also explains why Point does not support binding: it cannot inherit DependencyObject, which contains the necessary infrastructure for DPs).

    There might be a way though - you could create a subclass of polygon and add a new DependencyProperty called "BindablePoints" which would be an observable collection (you would have to create a custom OC that would fire CollectionChanged when one of the points changed) of the points. The property would in its OnChanged update the main Points property of the Polygon.

    I guess this could work, but I'm not sure whether it would be fast enough for whatever you are trying to do. Tou would still have to create subclasses of all the shapes you would want to use, but you wouldn't have to create them all from scratch.

提交回复
热议问题