I'm trying to make a button which resizes the window when it is dragged, just like the bottom right corner of a window.
I tried using the .MouseMove and .MouseDown events, but it doesn't work. Here is an example of my code:
void ButtonResize_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point pos = e.GetPosition(Window);
Window.Width += (pos - MousePos_OLD).X;
Window.Height += (pos - MousePos_OLD).Y;
}
MousePos_OLD = e.GetPosition(Window);
}
I also tried using the MouseDown event, and a MouseMove event was taking care of updating the mouse position, but nothing...
So how can I do this in WPF?
There exists a Control for that: a Thumb:
It containes an event events DragDelta which is what you search for.
EDIT:
to customize his visualization you can set him a Style
<Style x:Key="ThumbStyle" TargetType="{x:Type Thumb}" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border BorderBrush="Black" BorderThickness="1" Background="Transparent"></Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With