WPF: How to set thumb behavior on canvas?
I would like to have a Canvas that supports the DragDelta event. My first idea how to do this is to create a ControlTemplate with a thumb. But I don't know how to do it right. How can I change the XAML below to compile it and what's the correct way to set the DragDelta event handler?
<UserControl.Resources>
<ControlTemplate x:Key="Transparent">
<Rectangle Fill="Transparent"/>
</ControlTemplate>
<ControlTemplate x:Key="ThumbCanvas" TargetType="{x:Type Canvas}">
<Grid>
<Thumb x:Name="CanvasThumb" Template="{StaticResource Transparent}" DragDelta="CanvasThumb_DragDelta"/>
<ContentPresenter Content="{TemplateBinding Content}"/>
<!--error MC3011: Cannot find the static member 'ContentProperty' on the type 'Canvas'.-->
</Grid>
</ControlTemplate>
</UserControl.Resources>
a source to share
Any control created by a panel does not have a template property as they have no visible components.
You can use the Thumb control inside the UserControl as you do and just adjust the UserControl's height / width based on the Thumb delta. To make this work correctly, you need to get the mouse position relative to the parent of the usercontrol, otherwise it won't work. i.e .: e.GetLocation (this.Parent);
You should probably increase the size and width on that finger as well. It is also recommended to place the cursor on it.
a source to share