I have a set of simple geometries in WPF (check mark, arrows, etc.) I have these defined by Path which is nice because they are actually rendered rather than being rasterized.

The trouble I have is that I want to be able to change some of the properties of the Path (the Fill in particular) and I'm struggle as to how to implement. Do I use Styles, do I have something that contains it like UserControl? I'll have a handful of these so I don't want to have a bunch of duplicate controls.

I can't actually have a type that derives from Path because the class is sealed. That was where I went first.

有帮助吗?

解决方案

So what finally worked was I created a control that derived from ViewBox. On the ViewBox I added a "FillBrush" dependency property of type Brush.

I then just stamp out instances of this control and fill it with Path objects that have the correct Data and bind their Fill property to the FillBrush dependency property.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top