Click here to Skip to main content
15,898,373 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: How i can know who the users connected in my application? Pin
ABitSmart23-May-09 4:29
ABitSmart23-May-09 4:29 
GeneralRe: How i can know who the users connected in my application? Pin
VisualLive23-May-09 7:10
VisualLive23-May-09 7:10 
QuestionHow to implement Drag and drop functionality using WPF Pin
Nekkantidivya22-May-09 18:57
Nekkantidivya22-May-09 18:57 
AnswerRe: How to implement Drag and drop functionality using WPF Pin
ABitSmart23-May-09 4:17
ABitSmart23-May-09 4:17 
AnswerRe: How to implement Drag and drop functionality using WPF Pin
derm223-May-09 8:39
derm223-May-09 8:39 
GeneralRe: How to implement Drag and drop functionality using WPF Pin
Mark Salsbery23-May-09 9:18
Mark Salsbery23-May-09 9:18 
GeneralRe: How to implement Drag and drop functionality using WPF Pin
derm224-May-09 5:42
derm224-May-09 5:42 
GeneralRe: How to implement Drag and drop functionality using WPF Pin
Mark Salsbery24-May-09 7:09
Mark Salsbery24-May-09 7:09 
derm2 wrote:
Starting your mousemove eventhandler with "if the mouse has moved" feels unelegant for me


I guess I read your original post wrong because I saw
"Save the mouse location on previewmousedwn".

It's at that point I'd do hittesting or whatever necessary to
determine if it's the start of a drag situation, and if so, capture
the mouse.


derm2 wrote:
I have never worked with a framework that fired mousemove events without the mouse moving before WPF.


I don't know what you're talking about there....there's no randomly fired
move events. Here's a very simple drag and drop example showing this:
<Grid >
    <Canvas >
        <TextBlock x:Name="textBlock" Text="0" Foreground="Black" />
        <Rectangle Canvas.Left="30" Canvas.Top="30" Width="50" Height="50"
                             Stroke="Red" StrokeThickness="2" Fill="#00000000"
                             MouseLeftButtonDown="Rectangle_MouseLeftButtonDown"
                             MouseLeftButtonUp="Rectangle_MouseLeftButtonUp"
                             MouseMove="Rectangle_MouseMove" />
    </Canvas>
</Grid>

Point anchorPoint;
Point currentPoint;
bool isInDrag = false;
int moveCount = 0;

private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    FrameworkElement element = sender as FrameworkElement;
    anchorPoint = e.GetPosition(null);
    element.CaptureMouse();
    isInDrag = true;
    e.Handled = true;
}

private void Rectangle_MouseMove(object sender, MouseEventArgs e)
{
    moveCount++;
    textBlock.Text = moveCount.ToString();

    if (isInDrag)
    {
        FrameworkElement element = sender as FrameworkElement;
        currentPoint = e.GetPosition(null);
        double x = System.Convert.ToDouble(element.GetValue(Canvas.LeftProperty));
        double y = System.Convert.ToDouble(element.GetValue(Canvas.TopProperty));
        element.SetValue(Canvas.LeftProperty, x + currentPoint.X - anchorPoint.X);
        element.SetValue(Canvas.TopProperty, y + currentPoint.Y - anchorPoint.Y);
        anchorPoint = currentPoint;
    }
}

private void Rectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    if (isInDrag)
    {
        FrameworkElement element = sender as FrameworkElement;
        element.ReleaseMouseCapture();
        isInDrag = false;
        e.Handled = true;
    }
}

No "fired mousemove events without the mouse moving" that I can see there.
Don't even have to check if the cursor moved because I know it did when I got the event...

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: How to implement Drag and drop functionality using WPF Pin
derm225-May-09 1:44
derm225-May-09 1:44 
GeneralRe: How to implement Drag and drop functionality using WPF Pin
Mark Salsbery25-May-09 6:45
Mark Salsbery25-May-09 6:45 
QuestionAnother M-V-VM question: lookups Pin
ml_black22-May-09 4:23
ml_black22-May-09 4:23 
AnswerRe: Another M-V-VM question: lookups Pin
Pete O'Hanlon22-May-09 4:36
mvePete O'Hanlon22-May-09 4:36 
GeneralRe: Another M-V-VM question: lookups Pin
ml_black22-May-09 4:48
ml_black22-May-09 4:48 
GeneralRe: Another M-V-VM question: lookups Pin
ml_black22-May-09 6:18
ml_black22-May-09 6:18 
GeneralRe: Another M-V-VM question: lookups Pin
Pete O'Hanlon22-May-09 11:40
mvePete O'Hanlon22-May-09 11:40 
QuestionMaskText box is not scrolling in scrollviewer, in WPF Pin
Asit Kumar Sinha22-May-09 2:28
Asit Kumar Sinha22-May-09 2:28 
AnswerRe: MaskText box is not scrolling in scrollviewer, in WPF Pin
Mark Salsbery22-May-09 6:31
Mark Salsbery22-May-09 6:31 
QuestionCreating this sort of style in WPF/Blend Pin
pancakesOfMassDeliciousness22-May-09 2:15
pancakesOfMassDeliciousness22-May-09 2:15 
AnswerRe: Creating this sort of style in WPF/Blend Pin
Mark Salsbery22-May-09 5:09
Mark Salsbery22-May-09 5:09 
AnswerRe: Creating this sort of style in WPF/Blend Pin
Gideon Engelberth22-May-09 15:12
Gideon Engelberth22-May-09 15:12 
AnswerRe: Creating this sort of style in WPF/Blend Pin
Unagii10-Feb-10 3:22
Unagii10-Feb-10 3:22 
GeneralRe: Creating this sort of style in WPF/Blend Pin
pancakesOfMassDeliciousness10-Feb-10 3:27
pancakesOfMassDeliciousness10-Feb-10 3:27 
GeneralRe: Creating this sort of style in WPF/Blend Pin
Unagii10-Feb-10 3:45
Unagii10-Feb-10 3:45 
GeneralOverview: WPF Pin
Kamal Gurnani22-May-09 0:44
Kamal Gurnani22-May-09 0:44 
GeneralRe: Overview: WPF Pin
Pete O'Hanlon22-May-09 0:58
mvePete O'Hanlon22-May-09 0:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.