[Xamarin] ]UI PropertyChanged > APP Dev

본문 바로가기

사이트 내 전체검색

APP Dev

[Xamarin] ]UI PropertyChanged

작성일 19-03-08 15:50

페이지 정보

작성자sbLAB 조회 1,634회 댓글 0건

본문


OnPropertyChanged 적용된 데이타 모델클래스를 정의하고,


ExPageViewModel.cs 


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace ex.ViewModels
{
    /// <summary>
    /// 데이타모델
    /// </summary>
    public class ExPageViewModel : INotifyPropertyChanged
    {
        string _loginName;

        public string LoginName
        {
            get { return _loginName; }
            set
            {
                _loginName = value;
                OnPropertyChanged(nameof(LoginName));
            }
        }

       
        //MVVM
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyChanged)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyChanged));
        }


        public ExPageViewModel() { }

        public ExPageViewModel(string loginName)
        {
            this._loginName = loginName;

        }

    }

}

☞ 전역변수로 모델클래스에 대한 instance 를 만들고, 


App.xaml.cs 


public static ExPageViewModel exPageViewlabelInfo = new ExPageViewModel(); 



ContentPage 페이지 xaml 를 꾸미고,
ExPage.xaml
<Label x:Name="lblName"  Text="{Binding LoginName}" />


☞아래와 같이 Behind cs 에서 Binding

ExPage.xaml.cs
//Bingding LoginName
this.BindingContext = new
{
	LoginName = App.exPageViewlabelInfo.LoginName
};








댓글목록

등록된 댓글이 없습니다.

Copyright © 소유하신 도메인. All rights reserved.
PC 버전으로 보기