[Xamarin] ]UI PropertyChanged > APP Dev

본문 바로가기
사이트 내 전체검색

APP Dev

[Xamarin] ]UI PropertyChanged

페이지 정보

작성자 sbLAB 댓글 0건 조회 1,611회 작성일 19-03-08 15:50

본문


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
};








댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
290
어제
513
최대
1,279
전체
222,853

그누보드5
Copyright © sebom.com All rights reserved.