728x90
반응형
728x170
▶ MainViewModel.cs
using System.ComponentModel;
using System.Windows.Input;
namespace TestProject;
/// <summary>
/// 메인 뷰 모델
/// </summary>
public class MainViewModel : INotifyPropertyChanged
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Event
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 속성 변경시 - PropertyChanged
/// <summary>
/// 속성 변경시
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 값
/// </summary>
private double value = 1;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 값 - Value
/// <summary>
/// 값
/// </summary>
public double Value
{
get
{
return this.value;
}
set
{
if(this.value != value)
{
this.value = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
}
}
}
#endregion
#region 곱하기 명령 - MultiplyCommand
/// <summary>
/// 곱하기 명령
/// </summary>
public ICommand MultiplyCommand { get; private set; }
#endregion
#region 나누기 명령 - DivideCommand
/// <summary>
/// 나누기 명령
/// </summary>
public ICommand DivideCommand { get; private set; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainViewModel()
/// <summary>
/// 생성자
/// </summary>
public MainViewModel()
{
MultiplyCommand = new Command(() => Value *= 2);
DivideCommand = new Command(() => Value /= 2);
}
#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">
<ContentPage.BindingContext>
<local:MainViewModel />
</ContentPage.BindingContext>
<StackLayout
HorizontalOptions="Center"
VerticalOptions="Center">
<Label
HorizontalOptions="Center"
FontSize="18"
Text="{Binding Value, StringFormat='값 : {0}'}" />
<Button
HorizontalOptions="Center"
Margin="0,10,0,0"
Text="2로 곱하기"
Command="{Binding MultiplyCommand}" />
<Button
HorizontalOptions="Center"
Margin="0,10,0,0"
Text="2로 나누기"
Command="{Binding DivideCommand}" />
</StackLayout>
</ContentPage>
728x90
반응형
그리드형(광고전용)
'C# > MAUI' 카테고리의 다른 글
[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 엘리먼트 : Pressed/Released 이벤트 사용하기 (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 |
[C#/MAUI/.NET6] WebView 클래스 : Reload 메소드를 사용해 컨텐츠 갱신하기 (0) | 2022.05.18 |
댓글을 달아 주세요