c# - create and move a point on canvas at once -
c# - create and move a point on canvas at once -
i got problem creating , moving point (an ellipse) in wpf mvvm.
right have relaycommand calls create point handler in vm creates command , executes it:
private void createpointhandler(mouseeventargs e) { addconnectionpointcommand addconnectionpointcommand = new addconnectionpointcommand(this, e); petrinetviewmodel.executecommand(addconnectionpointcommand); }
furthermore existing point, got move handler aswell (in vm tho):
public void movepointhandler(connectionpoint pointmoved, point oldlocation, point newlocation) { vector move = new vector(newlocation.x - oldlocation.x, newlocation.y - oldlocation.y); petrinetviewmodel.executecommand(new movedragcanvaselementscommand(new connectionpoint[] { pointmoved }, move)); }
adding , moving point afterwards working expected.
now want give user possibility add together , move point in 1 step. in createpointhandler
can figure out if left mouse buttin still pressed this:
if (e.leftbutton == mousebuttonstate.pressed) { }
but how move point now? movepointhandler
called event in codebehind (i know shouldnt done in mvvm, collegues , think it's ok if don't have much code in it), passing elementsmovedeventargs
dont have here.
thanks help in advance.
it's hard without seeing codebehind calls these handlers.
i have thought should have concept of selectedpoint, @ can check if there intended drag happening when mouse moved.
i.e.
private connectionpoint selectedpoint { get; set; } private void onmousemove(object sender, mouseeventargs e) { if (e.leftbutton == mousebuttonstate.pressed) { // dragging something.. check if there point selected if (selectedpoint != null) { _viewmodel.movepointhandler(selectedpoint, _oldlocation, _newlocation); } } }
then, part of createpointhandler, set newly created instance selectedpoint, until mouseup detected.
private void executeaddconnectionpointcommand() { // standard logic... connectionpoint addedpoint = ... selectedpoint = addedpoint; }
the specifics of implementation alter depending on architecture, point.
c# wpf mvvm
Comments
Post a Comment