I’m asking this question after reading this answer on StackOverflow.
The supplied answer works great for allow you to move a whole control. But supposed I have a Usercontrol I’ve created like so:
<UserControl x:Class='WpfTest.UserControl1' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Height='300' Width='300'> <Border Background='Blue'> <Grid> <Grid.ColumnDefinitions> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height='26'></RowDefinition> <RowDefinition Height='*'></RowDefinition> </Grid.RowDefinitions> <Canvas Grid.Row='0' Background='orange'></Canvas> <Canvas Grid.Row='1' Background='Purple'></Canvas> </Grid> </Border> </UserControl>
I only want the control to move when I’m mouse clicking on the header part of the control, Grid.Row[0] (orange part). I don’t want the control to respond to drag operations when clicking on the rest of the control.
How can I accomplish this?
So, after some digging around, I solved my problem. The solution was to utilize a Thumb.
My UserControl XAML looks like this:
We can see the addition of the Thumb with a different color, which covers up the orange header (letting me know the thumb is actually there).
Code behind for the Thumb events looks like this:
And this got me exactly what I wanted. One question did remain: I see some tearing of the usercontrol when I move it around. It’s just not a smooth drawing effect, and I can’t seem to find a way to eliminate that. Any clues?