728x90
반응형
728x170
▶ PanContentView.cs
namespace TestProject;
/// <summary>
/// 패닝 컨텐트 뷰
/// </summary>
public class PanContentView : ContentView
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 현재 X
/// </summary>
private double currentX;
/// <summary>
/// 현재 Y
/// </summary>
private double currentY;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - PanContentView()
/// <summary>
/// 생성자
/// </summary>
public PanContentView()
{
PanGestureRecognizer recognizer = new PanGestureRecognizer();
recognizer.PanUpdated += recognizer_PanUpdated;
GestureRecognizers.Add(recognizer);
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 인식기 패닝 업데이트시 처리하기 - recognizer_PanUpdated(sender, e)
/// <summary>
/// 인식기 패닝 업데이트시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void recognizer_PanUpdated(object sender, PanUpdatedEventArgs e)
{
switch(e.StatusType)
{
case GestureStatus.Running :
Content.TranslationX = Math.Max(Math.Min(0, this.currentX + e.TotalX), -Math.Abs(Content.Width - DeviceDisplay.MainDisplayInfo.Width ));
Content.TranslationY = Math.Max(Math.Min(0, this.currentY + e.TotalY), -Math.Abs(Content.Height - DeviceDisplay.MainDisplayInfo.Height));
break;
case GestureStatus.Completed :
this.currentX = Content.TranslationX;
this.currentY = Content.TranslationY;
break;
}
}
#endregion
}
728x90
▶ MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="TestProject.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TestProject">
<AbsoluteLayout>
<local:PanContentView>
<Image Source="source.png"
WidthRequest="1920"
HeightRequest="1280" />
</local:PanContentView>
</AbsoluteLayout>
</ContentPage>
728x90
반응형
그리드형(광고전용)
'C# > MAUI' 카테고리의 다른 글
[C#/MAUI/.NET6] Tab 엘리먼트 사용하기 (0) | 2022.05.01 |
---|---|
[C#/MAUI/.NET6] FlyoutItem 엘리먼트 사용하기 (0) | 2022.05.01 |
[C#/MAUI/.NET6] TapGestureRecognizer 클래스 : Tapped 이벤트를 사용해 탭 처리하기 (0) | 2022.03.19 |
[C#/MAUI/.NET6] SwipeGestureRecognizer 클래스 : Swiped 이벤트를 사용해 스와이프 처리하기 (0) | 2022.03.18 |
[C#/MAUI/.NET6] PinchGestureRecognizer 클래스 : PinchUpdated 업데이트를 사용해 핀치 처리하기 (0) | 2022.03.18 |
[C#/MAUI/.NET6] DeviceDisplay 클래스 : MainDisplayInfo 속성을 사용해 화면 크기 구하기 (0) | 2022.03.18 |
[C#/MAUI/.NET6] DragGestureRecognizer 클래스 : DragStarting 이벤트를 사용해 드래그 시작시 처리하기 (0) | 2022.03.17 |
[C#/MAUI/.NET6] x:DataType 속성 : 컴파일된 바인딩과 클래식 바인딩 함께 사용하기 (0) | 2022.03.13 |
[C#/MAUI/.NET6] x:DataType 속성 : DataTemplate 엘리먼트에서 사용하기 (0) | 2022.03.13 |
[C#/MAUI/.NET6] x:DataType 속성 : 컴파일된 바인딩 사용하기 (0) | 2022.03.13 |
댓글을 달아 주세요