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

■ MultiBinding 클래스의 StringFormat 속성을 사용하는 방법을 보여준다.

TestProject.zip
0.15MB

▶ Employee.cs

namespace TestProject
{
    /// <summary>
    /// 직원
    /// </summary>
    public class Employee
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 이름 - FirstName

        /// <summary>
        /// 이름
        /// </summary>
        public string FirstName { get; set; }

        #endregion
        #region 성 - LastName

        /// <summary>
        /// 성
        /// </summary>
        public string LastName { get; set; }

        #endregion
    }
}

 

▶ 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"
        FontSize="32" />
</ContentPage>

 

▶ MainPage.xaml.cs

using System.Collections.ObjectModel;

namespace TestProject;

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

    #region 생성자 - MainPage()

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

        BindingContext = new Employee
        {
            FirstName = "길동",
            LastName  = "홍"
        };

        this.label.SetBinding
        (
            Label.TextProperty,
            new MultiBinding
            {
                Bindings = new Collection<BindingBase>
                {
                    new Binding("LastName" ),
                    new Binding("FirstName")
                },
                StringFormat = "{0} {1}"
            }
        );
    }

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

댓글을 달아 주세요