[Xamarin] ]UI PropertyChanged
작성일 19-03-08 15:50
페이지 정보
작성자sbLAB 조회 1,635회 댓글 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
};
댓글목록
등록된 댓글이 없습니다.