Drag&Drop 컨트롤 |
Drag&Drop 컨트롤 사용 방법)
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Canvas x:Name="lblName" Width="400" Height="300" Background="Silver"> <TextBlock Name="txtDrag" Text="DrageDrop" FontSize="30"></TextBlock> </Canvas> </UserControl> Drag&Drop. Cs using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace RiaDragDrop { public partial class MainPage : UserControl { private bool isMouseDown = false; //마우스 클릭 중인지 확인 private Point lastPoint = new Point(); //마지막 커서 위치 private Point offset = new Point(); //왼쪽 상단과 개체의 간격 여백 public MainPage() { InitializeComponent(); //[1]Left Button this.txtDrag.MouseLeftButtonDown += new MouseButtonEventHandler //[2]mouse Move this.txtDrag.MouseMove += new MouseEventHandler(txtDrag_MouseMove); ////left over this.txtDrag.MouseLeftButtonUp += new MouseButtonEventHandler } //Mouse Over void txtDrag_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { isMouseDown = false; //클릭되지 않은 상태 } //Mouse Move void txtDrag_MouseMove(object sender, MouseEventArgs e) { if (isMouseDown) // 마우스 클릭상태에서만 드래그 lastPoint = e.GetPosition(null); //재 설정 //TextBlock의C Left와 속성 재지정 txtDrag.SetValue(Canvas.LeftProperty, lastPoint.X - offset.X); txtDrag.SetValue(Canvas.TopProperty, lastPoint.Y - offset.Y); } } //Mouse Down void txtDrag_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { isMouseDown = true; //클릭된 상태 lastPoint = e.GetPosition(null); offset.X = lastPoint.X - Convert.ToDouble offset.Y = lastPoint.Y - Convert.ToDouble } } } |
'.Net Project > SilverLight 3.0' 카테고리의 다른 글
47장 RoutedEventArgs 컨트롤 (0) | 2009.12.01 |
---|---|
46장 InkPresenter 컨트롤 (0) | 2009.12.01 |
42장) ScrollViewer 컨트롤 (0) | 2009.12.01 |
41장) ToolTip 컨트롤 (0) | 2009.12.01 |
40장) 다시 보는 Canvas 예제 (복습) (0) | 2009.12.01 |