views:

1013

answers:

3

I currently try to create classes for a paint-like WPF application. I have to base classes LineMovement (line from StartPoint to EndPoint) and PathMovement (line going through all points specified in a property Points of type PointCollection). These classes inherit from Control and get their looks through a ControlTemplate.

The ControlTemplate also adds an Adorner to the AdornerLayer of the Movement objects containing a little visual marker for every moveable point of the specific line. These markers support dragging with a mouse.

The problem I have is that somehow my Movement classes don't repaint when their points are moved. I debugged my code with Mole and found out that the Polyline used to visualize the line gets the changed point values (visible in its Points property) but it just doesn't repaint.

How can I force a repaint of a WPF control?

A: 

You need to make your Movement objects' DPs have the AffectsArrange metadata property (http://msdn.microsoft.com/en-us/library/system.windows.frameworkpropertymetadataoptions.aspx) - that way when the property changes, WPF knows it should redraw

Paul Betts
Already tried that. It still doesn't help :(. The really strange thing is that when I use Mole to look into the Polyline representing the movement that its Point collection shows the changed point but it isn't repainted. When I use Mole to "edit" (aka take the string without any change and press the "Save" button) the PointsCollection of the Polyline it repaints as it should.
chrischu
+1  A: 

Turns out that TemplateBinding is pure evil.

When I bind the Points of the Polyline by {TemplateBinding Points} it doesn't update itself, whereas when I bind it with {Binding RelativeSource={RelativeSource TemplatedParent}} it works perfectly.

Note to myself: Never use this goddamn TemplateBinding again.

chrischu
+1  A: 

TemplateBinding doesn't support two-way data binding (i.e. updating the Points collection with the new values of the Polyline). It's meant only for one-way data binding for use in control templates. See Bea Stollnitz's blog entry: http://bea.stollnitz.com/blog/?p=38

Joe Strommen