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

TestProject.zip
0.15MB

▶ 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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요