728x90
반응형
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">
<StackLayout
HorizontalOptions="Center"
VerticalOptions="Center">
<Button x:Name="rotateButton"
HorizontalOptions="Center"
Text="텍스트 회전" />
<Label x:Name="label"
HorizontalOptions="Center"
Margin="0,100,0,0"
FontSize="18"
Text="버튼을 누르고 있으면 됩니다." />
</StackLayout>
</ContentPage>
728x90
▶ MainPage.xaml.cs
using Microsoft.Maui.Dispatching;
using System.Diagnostics;
namespace TestProject;
/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 타이머
/// </summary>
private IDispatcherTimer timer;
/// <summary>
/// 스톱워치
/// </summary>
private Stopwatch stopwatch = new Stopwatch();
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainPage()
/// <summary>
/// 생성자
/// </summary>
public MainPage()
{
InitializeComponent();
this.timer = Dispatcher.CreateTimer();
this.timer.Interval = TimeSpan.FromMilliseconds(16);
this.rotateButton.Pressed += rotateButton_Pressed;
this.rotateButton.Released += rotateButton_Released;
this.timer.Tick += timer_Tick;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 회전 버튼 PRESS 처리하기 - rotateButton_Pressed(sender, e)
/// <summary>
/// 회전 버튼 PRESS 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void rotateButton_Pressed(object sender, EventArgs e)
{
this.stopwatch.Start();
this.timer.Start();
}
#endregion
#region 회전 버튼 RELEASE 처리하기 - rotateButton_Released(sender, e)
/// <summary>
/// 회전 버튼 RELEASE 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void rotateButton_Released(object sender, EventArgs e)
{
this.stopwatch.Stop();
this.timer.Stop();
}
#endregion
#region 타이머 틱 처리하기 - timer_Tick(sender, e)
/// <summary>
/// 타이머 틱 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void timer_Tick(object sender, EventArgs e)
{
this.label.Rotation = 360 * (this.stopwatch.Elapsed.TotalSeconds % 1);
}
#endregion
}
728x90
반응형
그리드형(광고전용)
'C# > MAUI' 카테고리의 다른 글
[C#/MAUI/.NET6] RadioButton 엘리먼트 사용하기 (0) | 2022.05.19 |
---|---|
[C#/MAUI/.NET6] VisualStateManager 엘리먼트 : VisualStateGroups 첨부 속성을 ImageButton 객체에서 사용하기 (0) | 2022.05.19 |
[C#/MAUI/.NET6] ImageButton 엘리먼트 사용하기 (0) | 2022.05.19 |
[C#/MAUI/.NET6] Button 엘리먼트 : ContentLayout 속성 사용하기 (0) | 2022.05.19 |
[C#/MAUI/.NET6] VisualStateManager 엘리먼트 : VisualStateGroups 첨부 속성을 Button 객체에서 사용하기 (0) | 2022.05.19 |
[C#/MAUI/.NET6] Button 엘리먼트 : Command 속성 사용하기 (0) | 2022.05.19 |
[C#/MAUI/.NET6] WebView 클래스 : EvaluateJavaScriptAsync 메소드를 사용해 자바 스크립트 실행하기 (0) | 2022.05.18 |
[C#/MAUI/.NET6] WebView 클래스 : 쿠키 설정하기 (0) | 2022.05.18 |
[C#/MAUI/.NET6] WebView 클래스 : GoForward 메소드 사용하기 (0) | 2022.05.18 |
[C#/MAUI/.NET6] WebView 클래스 : GoBack 메소드 사용하기 (0) | 2022.05.18 |
댓글을 달아 주세요