첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
4.14MB

▶ 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">
    <Grid
        HorizontalOptions="Center"
        VerticalOptions="Center">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="50"   />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Image x:Name="sourceImage" Grid.Row="0" Grid.Column="0"
            WidthRequest="150"
            Source="source.png">
            <Image.GestureRecognizers>
                <DragGestureRecognizer x:Name="dragGestureRecognizer" />
            </Image.GestureRecognizers>
        </Image>
        <Image x:Name="targetImage" Grid.Row="0" Grid.Column="2"
            WidthRequest="150"
            Source="target.png">
            <Image.GestureRecognizers>
                <DropGestureRecognizer  x:Name="dropGestureRecognizer" />
            </Image.GestureRecognizers>
        </Image>
        <Label x:Name="label" Grid.Row="1" Grid.ColumnSpan="3" />
    </Grid>
</ContentPage>

 

728x90

 

▶ MainPage.xaml.cs

namespace TestProject;

/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 생성자 - MainPage()

    /// <summary>
    /// 생성자
    /// </summary>
    public MainPage()
    {
        InitializeComponent();

        this.dragGestureRecognizer.DragStarting += dragGestureRecognizer_DragStarting;
        this.dropGestureRecognizer.Drop         += dropGestureRecognizer_Drop;
    }

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region 드래그 제스처 인식기 드래그 시작시 처리하기 - dragGestureRecognizer_DragStarting(sender, e)

    /// <summary>
    /// 드래그 제스처 인식기 드래그 시작시 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private void dragGestureRecognizer_DragStarting(object sender, DragStartingEventArgs e)
    {        
        e.Data.Properties.Add("time", DateTime.Now.ToString());
    }

    #endregion
    #region 드롭 제스처 인식기 드롭시 처리하기 - dropGestureRecognizer_Drop(sender, e)

    /// <summary>
    /// 드롭 제스처 인식기 드롭시 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private async void dropGestureRecognizer_Drop(object sender, DropEventArgs e)
    {
        this.label.Text = e.Data.Properties["time"] as string;

        this.targetImage.Source = await e.Data.GetImageAsync();
    }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요