locked
How to move multiple border control which we are creating dynamically over a stackpanel?

    Question

  • Hello! Greeting to all of you!

    We are trying to move multiple border control dynamically with in a stack panel. It works partially and sometime it gets stuck and mouse gets stick with the control even we release...

    Here is the code we are using.. Please suggest on the resolution or give us pointer.. Any help in this regard will be much appreciated?

    Point positionWithinImage;
    Point StackPanelpositionWithinImage;
    bool holding = false;

    private void Panel_PointerPressed(object sender, PointerRoutedEventArgs e)
    {
        holding = true;
        objBorder.Name = (sender as Border).Name;
        (sender as Border).PointerMoved += PanelView1_PointerMoved;
        positionWithinImage = e.GetCurrentPoint(sender as Border).Position;
        (sender as Border).PointerExited += Dashboard_PointerExited;
    }

    private void Dashboard_PointerExited(object sender, PointerRoutedEventArgs e)
    {
        holding = false;
        (sender as Border).PointerMoved -= PanelView1_PointerMoved;
        (sender as Border).PointerExited -= Dashboard_PointerExited;
    }

    private void PanelView1_PointerMoved(object sender, PointerRoutedEventArgs e)
    {
        if (holding)
        {
        Border b = ((sender) as Border);
        var pos = e.GetCurrentPoint(sender as Border).Position;
        b.Margin = new Thickness((sender as Border).Margin.Left + (pos.X - this.positionWithinImage.X), (sender as Border).Margin.Top + (pos.Y - this.positionWithinImage.Y), 0, 0);
        }
    }

    Wednesday, November 12, 2014 7:57 AM

Answers

  • Hi Snaps Technology,

    Could you share us a reproducible demo that we can simply test on it, without knowing how you create the border and how you layout the stackpanel, hardly for us to give more suggestions.

    However you mentioned "sometime it gets stuck and mouse gets stick with the control even we release" sounds like the control doesn't unregister the event, actually I did not see any release event (PointerRelease) for the mouse click, I believe that could be the problem

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Thursday, November 13, 2014 1:44 AM
    Moderator