첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
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">
    <Label x:Name="label"
        HorizontalOptions="Center"
        VerticalOptions="Center"
        Text="" />
</ContentPage>

 

TestProject.zip
0.15MB

 

▶ MainPage.xaml.cs

using System.Text;

namespace TestProject;

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

    #region 생성자 - MainPage()

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

        this.label.Text = GetMessage(Connectivity.Current.NetworkAccess, Connectivity.Current.ConnectionProfiles);

        Connectivity.ConnectivityChanged += connectivity_ConnectivityChanged;
    }

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Private
    //////////////////////////////////////////////////////////////////////////////// Event

    #region 연결 변경시 처리하기 - connectivity_ConnectivityChanged(sender, e)

    /// <summary>
    /// 연결 변경시 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private void connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
    {
        this.label.Text = GetMessage(e.NetworkAccess, e.ConnectionProfiles);
    }

    #endregion

    //////////////////////////////////////////////////////////////////////////////// Function

    #region 메시지 구하기 - GetMessage(networkAccess, profileEnumerable)

    /// <summary>
    /// 메시지 구하기
    /// </summary>
    /// <param name="networkAccess">네트워크 액세스</param>
    /// <param name="profileEnumerable">프로필 열거 가능형</param>
    /// <returns>메시지</returns>
    private string GetMessage(NetworkAccess networkAccess, IEnumerable<ConnectionProfile> profileEnumerable)
    {
        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.AppendLine($"네트워크 액세스 : {networkAccess}");
        stringBuilder.AppendLine( "연결 프로필");

        foreach(ConnectionProfile profile in profileEnumerable)
        {
            stringBuilder.AppendLine($"    {profile}");
        }

        return stringBuilder.ToString();
    }

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

댓글을 달아 주세요