I am trying to implement a custom control (Templated Control) for a UWP application for transforming shapes (mostly Rectangle types). Custom control will be implemented in a UWP class library and reference to the main project. What I want to achieve is draw the custom control around another basic shape (eg: Rectangle) and transform the shape according to the manipulations done on the custom control.
I am trying to implement the control with manipulation events (ManipulationDelta, ManipulationCompleted).
I was able to achieve a similar behavior using pointer related events(PointerPressed, PointerMoved, PointerReleased) but it is not very smooth & I want to integrate this control with other applications easily.
Please find the sample source code here.
When I try to move the control the manipulation events are not firing, and I cannot figure out the reason.
I started to work on UWP applications recently and any help on this matter is highly appreciated.
In your scenario, there are several removing codes in
PointPressed
event, such as“RootCanvas.Children.Remove()”
. When you move the control, the PointPressed event is triggered, the previous generated rectangle named resizableRectV2 is deleted. So theresizableRectV2.ManipulationCompleted
event will not be triggered.In addition, I suggest that you don’t create two completely overlapping rectangles, which makes you confused.
Update:
SpeakerView.xaml.cs:
I mean that you could delete the above code in OnPointerPressed event.