728x90
반응형
728x170
▶ TestWindow.xaml
<Window
x:Class="DS.Test.WPF.TestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeToContent="WidthAndHeight">
<Canvas
Name="canvas"
Width="300"
Height="300">
<Thumb
Name="thumb"
Canvas.Left="280"
Canvas.Top="280"
Width="20"
Height="20"
Background="Blue"
DragStarted="thumb_DragStarted"
DragDelta="thumb_DragDelta"
DragCompleted="thumb_DragCompleted" />
</Canvas>
</Window>
728x90
▶ TestWindow.xaml.cs
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace DS.Test.WPF
{
/// <summary>
/// 테스트 윈도우
/// </summary>
public partial class TestWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - TestWindow()
/// <summary>
/// 생성자
/// </summary>
public TestWindow()
{
InitializeComponent();
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Thumb 드래그 시작시 처리하기 - thumb_DragStarted(sender, e)
/// <summary>
/// Thumb 드래그 시작시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void thumb_DragStarted(object sender, DragStartedEventArgs e)
{
this.thumb.Background = Brushes.Orange;
}
#endregion
#region Thumb 드래그 변화시 처리하기 - thumb_DragDelta(sender, e)
/// <summary>
/// Thumb 드래그 변화시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void thumb_DragDelta(object sender, DragDeltaEventArgs e)
{
double newCanvasWidth = this.canvas.Width + e.HorizontalChange;
double newCanvasHeight = this.canvas.Height + e.VerticalChange;
if((newCanvasWidth >= 0) && (newCanvasHeight >= 0))
{
this.canvas.Width = newCanvasWidth;
this.canvas.Height = newCanvasHeight;
Canvas.SetLeft(this.thumb, Canvas.GetLeft(this.thumb) + e.HorizontalChange);
Canvas.SetTop (this.thumb, Canvas.GetTop (this.thumb) + e.VerticalChange );
}
}
#endregion
#region Thumb 드래그 완료시 처리하기 - thumb_DragCompleted(sender, e)
/// <summary>
/// Thumb 드래그 완료시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void thumb_DragCompleted(object sender, DragCompletedEventArgs e)
{
this.thumb.Background = Brushes.Blue;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] CollectionViewSource 엘리먼트 사용하기 (0) | 2014.01.31 |
---|---|
[C#/WPF] INotifyPropertyChanged, IEditableObject 인터페이스 구현 객체 정의하기 (0) | 2014.01.31 |
[C#/WPF] DataGrid 엘리먼트 : 행 세부 정보 섹션 가로 스크롤 방지하기 (0) | 2014.01.31 |
[C#/WPF] DataGrid 엘리먼트 : RowDetailsVisibilityMode 속성 사용하기 (0) | 2014.01.31 |
[C#/WPF] DataGrid 엘리먼트 : RowDetailsTemplate 속성 사용하기 (0) | 2014.01.31 |
[C#/WPF] BulletDecorator 엘리먼트 사용하기 (0) | 2014.01.31 |
[C#/WPF] Label 엘리먼트 : Target 속성 사용하기 (0) | 2014.01.31 |
[C#/WPF] CroppedBitmap 클래스 : 비트맵 소스에서 비트맵 잘라내기 (0) | 2014.01.31 |
[C#/WPF] CroppedBitmap 엘리먼트 : SourceRect 속성 사용하기 (0) | 2014.01.31 |
[C#/WPF] FormatConvertedBitmap 클래스 : 비트맵 소스 픽셀 포맷 변경하기 (0) | 2014.01.31 |
댓글을 달아 주세요