[C#/MAUI/.NET6] DrawingView 클래스 : DrawingLineCompleted 이벤트를 사용해 선 그리기 완료시 처리하기
C#/MAUI 2022. 7. 31. 20:57728x90
반응형
728x170
▶ 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:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
<Grid
Margin="10"
RowDefinitions="*,10,*">
<toolkit:DrawingView x:Name="drawingView" Grid.Row="0"
Margin="10"
Background="Beige"
IsMultiLineModeEnabled="true"
ShouldClearOnFinish="false"
LineWidth="5"
LineColor="Blue" />
<Image x:Name="image" Grid.Row="2" />
</Grid>
</ContentPage>
300x250
▶ MainPage.xaml.cs
using System.Collections.ObjectModel;
using CommunityToolkit.Maui.Core;
namespace TestProject;
/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainPage()
/// <summary>
/// 생성자
/// </summary>
public MainPage()
{
InitializeComponent();
this.drawingView.Lines = new ObservableCollection<IDrawingLine>();
this.drawingView.DrawingLineCompleted += drawingView_DrawingLineCompleted;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 드로잉 뷰 선 그리기 완료시 처리하기 - drawingView_DrawingLineCompleted(sender, e)
/// <summary>
/// 드로잉 뷰 선 그리기 완료시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private async void drawingView_DrawingLineCompleted(object sender, DrawingLineCompletedEventArgs e)
{
Stream stream = await e.LastDrawingLine.GetImageStream(this.image.Width, this.image.Height, Colors.Gray.AsPaint());
this.image.Source = ImageSource.FromStream(() => stream);
}
#endregion
}
728x90
▶ MauiProgram.cs
using CommunityToolkit.Maui;
namespace TestProject;
/// <summary>
/// MAUI 프로그램
/// </summary>
public static class MauiProgram
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region MAUI 앱 생성하기 - CreateMauiApp()
/// <summary>
/// MAUI 앱 생성하기
/// </summary>
/// <returns>MAUI 앱</returns>
public static MauiApp CreateMauiApp()
{
MauiAppBuilder builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureFonts
(
fontCollection =>
{
fontCollection.AddFont("OpenSans-Regular.ttf" , "OpenSansRegular" );
fontCollection.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
}
);
return builder.Build();
}
#endregion
}
728x90
반응형
그리드형(광고전용)
댓글을 달아 주세요