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">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackLayout Grid.Row="0"
Margin="10"
HorizontalOptions="Center">
<Button
HorizontalOptions="Center"
Text="Slider 객체 생성"
CommandParameter="{x:Type Slider}"
Command="{Binding CreateCommand}" />
<Button
Margin="0,10,0,0"
HorizontalOptions="Center"
Text="Stepper 객체 생성"
CommandParameter="{x:Type Stepper}"
Command="{Binding CreateCommand}" />
<Button
Margin="0,10,0,0"
HorizontalOptions="Center"
Text="Switch 객체 생성"
CommandParameter="{x:Type Switch}"
Command="{Binding CreateCommand}" />
</StackLayout>
<ScrollView Grid.Row="1">
<StackLayout x:Name="stackLayout" />
</ScrollView>
</Grid>
</ContentPage>
728x90
▶ MainPage.xaml.cs
using System.Windows.Input;
namespace TestProject;
/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성 명령 - CreateCommand
/// <summary>
/// 생성 명령
/// </summary>
public ICommand CreateCommand { get; private set; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainPage()
/// <summary>
/// 생성자
/// </summary>
public MainPage()
{
InitializeComponent();
CreateCommand = new Command<Type>
(
(Type viewType) =>
{
View view = (View)Activator.CreateInstance(viewType);
view.Margin = new Thickness(10);
view.HorizontalOptions = LayoutOptions.Fill;
this.stackLayout.Add(view);
}
);
BindingContext = this;
}
#endregion
}
728x90
반응형
그리드형(광고전용)
'C# > MAUI' 카테고리의 다른 글
[C#/MAUI/.NET6] DataTemplate 태그 확장 사용하기 (0) | 2022.03.03 |
---|---|
[C#/MAUI/.NET6] OnIdiom 태그 확장 사용하기 (0) | 2022.03.03 |
[C#/MAUI/.NET6] OnPlatform 태그 확장 : double 값 설정하기 (0) | 2022.03.03 |
[C#/MAUI/.NET6] x:Null 태그 확장 사용하기 (0) | 2022.03.03 |
[C#/MAUI/.NET6] x:Array 엘리먼트 : 색상 배열 사용하기 (0) | 2022.03.03 |
[C#/MAUI/.NET6] x:Reference 태그 확장 사용하기 (0) | 2022.03.03 |
[C#/MAUI/.NET6] x:Static 태그 확장 : 정적 필드 참조하기 (0) | 2022.03.03 |
[C#/MAUI/.NET6] x:StaticExtension 태그 확장 : Member 속성을 사용해 정적 필드 참조하기 (0) | 2022.03.03 |
[C#/MAUI/.NET6] x:Static 엘리먼트 : Member 속성 사용하기 (0) | 2022.03.03 |
[C#/MAUI/.NET6] x:StaticExtension 엘리먼트 : Member 속성을 사용해 정적 필드 참조하기 (0) | 2022.03.03 |
댓글을 달아 주세요