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

TestProject.zip
0.15MB

▶ App.xaml

<Application x:Class="TestProject.App"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:TestProject">
</Application>

 

728x90

 

▶ App.xaml.cs

namespace TestProject;

/// <summary>
/// 앱
/// </summary>
public partial class App : Application
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 생성자 - App()

    /// <summary>
    /// 생성자
    /// </summary>
    public App()
    {
        InitializeComponent();

        NavigationPage navigationPage = new NavigationPage(new MainPage());

        navigationPage.BarTextColor = Colors.White;

        MainPage = navigationPage;
    }

    #endregion
}

 

300x250

 

▶ 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"
    Title="메인 페이지">
    <Button x:Name="navigateButton"
        HorizontalOptions="Center"
        VerticalOptions="Center"
        Text="두번째 페이지 이동하기" />
</ContentPage>

 

반응형

 

▶ MainPage.xaml.cs

namespace TestProject;

/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 생성자 - MainPage()

    /// <summary>
    /// 생성자
    /// </summary>
    public MainPage()
    {
        InitializeComponent();

        this.navigateButton.Clicked += navigateButton_Clicked;
    }

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region 페이지 이동 버튼 클릭시 처리하기 - navigateButton_Clicked(sender, e)

    /// <summary>
    /// 페이지 이동 버튼 클릭시 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private async void navigateButton_Clicked(object sender, EventArgs e)
    {
        string xaml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<ContentPage
    xmlns=""http://schemas.microsoft.com/dotnet/2021/maui""
    xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""
    Title=""두번째 페이지"">
    <StackLayout
        HorizontalOptions=""Center""
        VerticalOptions=""Center"">
        <Label x:Name=""monkeyLabel"" />
    </StackLayout>
</ContentPage>
";

        ContentPage page = new ContentPage().LoadFromXaml(xaml);

        Label monkeyLabel = page.FindByName<Label>("monkeyLabel");

        monkeyLabel.Text = "앉아있는 원숭이";

        await Navigation.PushAsync(page);
    }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요