Click here to Skip to main content
15,886,673 members
Home / Discussions / WPF
   

WPF

 
QuestionKeep element in canvas when dragging it Pin
Pauwels Bart1-Apr-09 20:19
Pauwels Bart1-Apr-09 20:19 
AnswerRe: Keep element in canvas when dragging it Pin
ABitSmart1-Apr-09 21:17
ABitSmart1-Apr-09 21:17 
QuestionRe: Keep element in canvas when dragging it Pin
Pauwels Bart1-Apr-09 23:30
Pauwels Bart1-Apr-09 23:30 
AnswerRe: Keep element in canvas when dragging it Pin
ABitSmart2-Apr-09 5:05
ABitSmart2-Apr-09 5:05 
QuestionRe: Keep element in canvas when dragging it Pin
Pauwels Bart2-Apr-09 7:22
Pauwels Bart2-Apr-09 7:22 
AnswerRe: Keep element in canvas when dragging it [modified] Pin
ABitSmart2-Apr-09 7:50
ABitSmart2-Apr-09 7:50 
GeneralRe: Keep element in canvas when dragging it Pin
Pauwels Bart2-Apr-09 8:45
Pauwels Bart2-Apr-09 8:45 
GeneralRe: Keep element in canvas when dragging it Pin
Pauwels Bart4-Apr-09 18:32
Pauwels Bart4-Apr-09 18:32 
Ok, the sender was not the element in the canvas but the thumb. Luckely I can get the element with "this.AdornedElement" (standard build-in adorner function to get the adorned element).

So, the solution was:
  // Handler for moving.
  private void HandleMove(object sender, DragDeltaEventArgs args)
  {
      FrameworkElement element = this.AdornedElement as FrameworkElement;
      StanagCanvas stanagCanvas = element.Parent as StanagCanvas;

      // Horizontal position.
      if (StanagCanvas.GetLeft(element) + args.HorizontalChange < 0)
      {
          // Crossing left boundary.
          StanagCanvas.SetLeft(element, 0);
      }
      else if (StanagCanvas.GetLeft(element) + element.Width + args.HorizontalChange > stanagCanvas.Width)
      {
          // Crossing right boundary.
          StanagCanvas.SetLeft(element, stanagCanvas.Width - element.Width);
      }
      else
      {
          StanagCanvas.SetLeft(element, StanagCanvas.GetLeft(element) + args.HorizontalChange);
      }

      // Vertical position.
      if (StanagCanvas.GetTop(element) + args.VerticalChange < 0)
      {
          // Crossing top boundary.
          StanagCanvas.SetTop(element, 0);
      }
      else if (StanagCanvas.GetTop(element) + element.Height + args.VerticalChange > stanagCanvas.Height)
      {
          // Crossing bottom boundary.
          StanagCanvas.SetBottom(element, stanagCanvas.Height - element.Height);
      }
      else
      {
          StanagCanvas.SetTop(element, StanagCanvas.GetTop(element) + args.VerticalChange);
      }
}


I just made it to difficult and overlooked this simple sollution! Now the element stays within the bounderies of the canvas.

thx ABitSmart
GeneralRe: Keep element in canvas when dragging it Pin
ABitSmart4-Apr-09 19:42
ABitSmart4-Apr-09 19:42 
GeneralRe: Keep element in canvas when dragging it Pin
Pauwels Bart4-Apr-09 19:54
Pauwels Bart4-Apr-09 19:54 
QuestionWPF or Windows Forms Pin
dfreeser1-Apr-09 12:00
dfreeser1-Apr-09 12:00 
AnswerRe: WPF or Windows Forms Pin
Pete O'Hanlon1-Apr-09 22:03
mvePete O'Hanlon1-Apr-09 22:03 
AnswerRe: WPF or Windows Forms Pin
RugbyLeague2-Apr-09 5:40
RugbyLeague2-Apr-09 5:40 
GeneralRe: WPF or Windows Forms Pin
dfreeser2-Apr-09 5:56
dfreeser2-Apr-09 5:56 
QuestionSet style definition dynamically Pin
salon1-Apr-09 3:46
salon1-Apr-09 3:46 
AnswerRe: Set style definition dynamically Pin
Mark Salsbery1-Apr-09 7:42
Mark Salsbery1-Apr-09 7:42 
GeneralRe: Set style definition dynamically Pin
salon1-Apr-09 20:48
salon1-Apr-09 20:48 
GeneralRe: Set style definition dynamically Pin
Mark Salsbery2-Apr-09 5:26
Mark Salsbery2-Apr-09 5:26 
QuestionSys.InvalidOprationException.ManageRunTimeError error #4004 in control 'Xaml1 Pin
Piyush Vardhan Singh1-Apr-09 0:17
Piyush Vardhan Singh1-Apr-09 0:17 
AnswerRe: Sys.InvalidOprationException.ManageRunTimeError error #4004 in control 'Xaml1 Pin
Piyush Vardhan Singh1-Apr-09 2:02
Piyush Vardhan Singh1-Apr-09 2:02 
QuestionHorizontal scrollbar in empty listview disappears Pin
Pankaj Chamria31-Mar-09 23:22
Pankaj Chamria31-Mar-09 23:22 
AnswerRe: Horizontal scrollbar in empty listview disappears Pin
ABitSmart1-Apr-09 1:03
ABitSmart1-Apr-09 1:03 
GeneralRe: Horizontal scrollbar in empty listview disappears Pin
Pankaj Chamria3-Apr-09 6:16
Pankaj Chamria3-Apr-09 6:16 
GeneralRe: Horizontal scrollbar in empty listview disappears Pin
ABitSmart3-Apr-09 6:33
ABitSmart3-Apr-09 6:33 
Questionhow assign theme in silverlight2? Pin
Piyush Vardhan Singh31-Mar-09 20:57
Piyush Vardhan Singh31-Mar-09 20:57 

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.