Click here to Skip to main content
15,911,132 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Isolated Storage Pin
Mark Salsbery24-May-09 8:34
Mark Salsbery24-May-09 8:34 
QuestionNeed some help to develop tetris game in asp.net as a web service using silverlight Pin
mirza asim24-May-09 2:00
mirza asim24-May-09 2:00 
AnswerRe: Need some help to develop tetris game in asp.net as a web service using silverlight Pin
Ray Cassick24-May-09 4:57
Ray Cassick24-May-09 4:57 
GeneralRe: Need some help to develop tetris game in asp.net as a web service using silverlight Pin
mirza asim24-May-09 20:54
mirza asim24-May-09 20:54 
QuestionDocking a treeview Pin
rehpot23-May-09 22:09
rehpot23-May-09 22:09 
AnswerRe: Docking a treeview Pin
ABitSmart24-May-09 21:37
ABitSmart24-May-09 21:37 
QuestionHow to develop Analog clock and Digital clock in WPF application Pin
Nekkantidivya23-May-09 1:50
Nekkantidivya23-May-09 1:50 
AnswerRe: How to develop Analog clock and Digital clock in WPF application Pin
ABitSmart23-May-09 4:14
ABitSmart23-May-09 4:14 
GeneralRe: How to develop Analog clock and Digital clock in WPF application Pin
Kevin McFarlane23-May-09 6:21
Kevin McFarlane23-May-09 6:21 
QuestionHow to get weather information into my WPF application Pin
Nekkantidivya22-May-09 21:36
Nekkantidivya22-May-09 21:36 
AnswerRe: How to get weather information into my WPF application Pin
ABitSmart23-May-09 4:15
ABitSmart23-May-09 4:15 
QuestionHow i can know who the users connected in my application? Pin
VisualLive22-May-09 19:03
VisualLive22-May-09 19:03 
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 

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.