SlideShare a Scribd company logo
1 of 6
Download to read offline
www.topcredu.co.kr
작성자 : 이종철
4.7.5 Xamarin.Forms
ListView 데이터 바인딩
 Model, ViewModel을 간단히 만들고 ViewModel을 ListView에 바인딩하는 간단한 예제를 작
성해 보자.
 사원의 사번과 이름을 입력하면 아래쪽 ListView에 바인딩되서 데이터가 뿌려지는 간단한 예
제로 실행화면은 다음과 같다.
 Emp.cs
namespace DataBindingTest
{
class Emp
{
public string Empno { get; set; }
public string Ename { get; set; }
public bool IsChecked { get; set; }
}
}
 EmpViewModel.cs
using System.Collections.ObjectModel;
namespace DataBindingTest
{
class EmpViewModel
{
// Collection의 변화(Add/Delete)를 자동으로 감지하여 UI화면을
자동갱신
// ObservableCollection은 INotyfyChanged 인터페이스를 구현했다.
// ListView를 자동으로 업데이트 하기위해 ObservableCollection을
사용.
private ObservableCollection<Emp> emps = new
ObservableCollection<Emp>();
public ObservableCollection<Emp> Emps
{
get
{
return emps;
}
set
{
emps = value;
}
}
public EmpViewModel()
{
Emps = new ObservableCollection<Emp>();
}
}
}
 MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:DataBindingTest"
x:Class="DataBindingTest.MainPage">
<Grid HorizontalOptions="Center">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="40"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Label Text="사번" Grid.Row="0" Grid.Column="0"
VerticalOptions="Center"/>
<Entry x:Name="txtEmpno" Grid.Row="0" Grid.Column="1"
VerticalOptions="Center"/>
<Label Text="이름" Grid.Row="0" Grid.Column="2"
VerticalOptions="Center"/>
<Entry x:Name="txtEname" Grid.Row="0" Grid.Column="3"
VerticalOptions="Center"/>
<Button x:Name="btnSave" Text="저장" Grid.Row="1"
Grid.ColumnSpan="4"
VerticalOptions="Center" Clicked="btnSave_Click"/>
<ListView x:Name="listView"
Grid.Row="3" Grid.ColumnSpan="4"
VerticalOptions="Center">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="{Binding
Empno}"></Label>
<Label Grid.Column="1" Text="{Binding
Ename}"></Label>
<Switch Grid.Column="2" IsToggled="{Binding
IsChecked}"></Switch>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ContentPage>
 MainPage.xaml.cs
using System;
using Xamarin.Forms;
namespace DataBindingTest
{
public partial class MainPage : ContentPage
{
EmpViewModel viewModel = new EmpViewModel();
public MainPage()
{
InitializeComponent();
listView.ItemsSource = viewModel.Emps;
//BindingContext = viewModel;
}
private void btnSave_Click(object sender, EventArgs e)
{
viewModel.Emps.Add(new Emp() { Empno = txtEmpno.Text,
Ename =txtEname.Text,
IsChecked = false});
txtEmpno.Text = "";
txtEname.Text = "";
}
}
}

More Related Content

More from 탑크리에듀(구로디지털단지역3번출구 2분거리)

[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)탑크리에듀(구로디지털단지역3번출구 2분거리)
 
(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...
(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...
(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...
C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...
C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]탑크리에듀(구로디지털단지역3번출구 2분거리)
 
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]탑크리에듀(구로디지털단지역3번출구 2분거리)
 

More from 탑크리에듀(구로디지털단지역3번출구 2분거리) (20)

자마린 iOS 멀티화면 컨트롤러_네비게이션 컨트롤러, 루트 뷰 컨트롤러
자마린 iOS 멀티화면 컨트롤러_네비게이션 컨트롤러, 루트 뷰 컨트롤러자마린 iOS 멀티화면 컨트롤러_네비게이션 컨트롤러, 루트 뷰 컨트롤러
자마린 iOS 멀티화면 컨트롤러_네비게이션 컨트롤러, 루트 뷰 컨트롤러
 
[IT교육/IT학원]Develope를 위한 IT실무교육
[IT교육/IT학원]Develope를 위한 IT실무교육[IT교육/IT학원]Develope를 위한 IT실무교육
[IT교육/IT학원]Develope를 위한 IT실무교육
 
[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)
[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)
[아이오닉학원]아이오닉 하이브리드 앱 개발 과정(아이오닉2로 동적 모바일 앱 만들기)
 
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
[뷰제이에스학원]뷰제이에스(Vue.js) 프로그래밍 입문(프로그레시브 자바스크립트 프레임워크)
 
[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정
[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정
[씨샵학원/씨샵교육]C#, 윈폼, 네트워크, ado.net 실무프로젝트 과정
 
[정보처리기사자격증학원]정보처리기사 취득 양성과정(국비무료 자격증과정)
[정보처리기사자격증학원]정보처리기사 취득 양성과정(국비무료 자격증과정)[정보처리기사자격증학원]정보처리기사 취득 양성과정(국비무료 자격증과정)
[정보처리기사자격증학원]정보처리기사 취득 양성과정(국비무료 자격증과정)
 
[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정
[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정
[wpf학원,wpf교육]닷넷, c#기반 wpf 프로그래밍 인터페이스구현 재직자 향상과정
 
(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...
(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...
(WPF교육)ListBox와 Linq 쿼리를 이용한 간단한 데이터바인딩, 새창 띄우기, 이벤트 및 델리게이트를 통한 메인윈도우의 ListB...
 
C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...
C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...
C#기초에서 윈도우, 스마트폰 앱개발 과정(c#.net, ado.net, win form, wpf, 자마린)_자마린학원_씨샵교육_WPF학원...
 
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
자바, 웹 기초와 스프링 프레임워크 & 마이바티스 재직자 향상과정(자바학원/자바교육/자바기업출강]
 
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...
3. xamarin.i os 3.1 xamarin.ios 설치, 개발환경 3.2 xamarin.ios helloworld_자마린학원_자마린...
 
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
3. 안드로이드 애플리케이션 구성요소 3.2인텐트 part01(안드로이드학원/안드로이드교육/안드로이드강좌/안드로이드기업출강]
 
2. xamarin.android 2.5.3 xamarin.android .aar binding(안드로이드 .aar file을 자마린 바...
2. xamarin.android  2.5.3 xamarin.android .aar binding(안드로이드 .aar file을 자마린 바...2. xamarin.android  2.5.3 xamarin.android .aar binding(안드로이드 .aar file을 자마린 바...
2. xamarin.android 2.5.3 xamarin.android .aar binding(안드로이드 .aar file을 자마린 바...
 
유니티,Unity 엔진을 활용한 VR/AR 콘텐츠 개발 _사물인터넷(IoT) 네크워크 프로그래밍
유니티,Unity 엔진을 활용한 VR/AR 콘텐츠 개발 _사물인터넷(IoT) 네크워크 프로그래밍유니티,Unity 엔진을 활용한 VR/AR 콘텐츠 개발 _사물인터넷(IoT) 네크워크 프로그래밍
유니티,Unity 엔진을 활용한 VR/AR 콘텐츠 개발 _사물인터넷(IoT) 네크워크 프로그래밍
 
2. xamarin.android 2.5 xamarin.android(with .jar, .aar, native android librar...
2. xamarin.android 2.5 xamarin.android(with .jar, .aar, native android librar...2. xamarin.android 2.5 xamarin.android(with .jar, .aar, native android librar...
2. xamarin.android 2.5 xamarin.android(with .jar, .aar, native android librar...
 
2. xamarin.android 2.5 xamarin.android(with .jar, .aar, native android librar...
2. xamarin.android 2.5 xamarin.android(with .jar, .aar, native android librar...2. xamarin.android 2.5 xamarin.android(with .jar, .aar, native android librar...
2. xamarin.android 2.5 xamarin.android(with .jar, .aar, native android librar...
 
2. xamarin.android 2.3 hello android multi screen example part2
2. xamarin.android 2.3 hello android multi screen example part22. xamarin.android 2.3 hello android multi screen example part2
2. xamarin.android 2.3 hello android multi screen example part2
 
2. xamarin.android 2.2 hello xamarin android 구조 2.2.7 simple intent example(현...
2. xamarin.android 2.2 hello xamarin android 구조 2.2.7 simple intent example(현...2. xamarin.android 2.2 hello xamarin android 구조 2.2.7 simple intent example(현...
2. xamarin.android 2.2 hello xamarin android 구조 2.2.7 simple intent example(현...
 
2. xamarin.android 2.2 hello xamarin android 구조 2.2.7 simple intent example(현...
2. xamarin.android 2.2 hello xamarin android 구조 2.2.7 simple intent example(현...2. xamarin.android 2.2 hello xamarin android 구조 2.2.7 simple intent example(현...
2. xamarin.android 2.2 hello xamarin android 구조 2.2.7 simple intent example(현...
 
2. xamarin.android 2.2 hello xamarin android 구조 2.2.6 simple intent example(웹...
2. xamarin.android 2.2 hello xamarin android 구조 2.2.6 simple intent example(웹...2. xamarin.android 2.2 hello xamarin android 구조 2.2.6 simple intent example(웹...
2. xamarin.android 2.2 hello xamarin android 구조 2.2.6 simple intent example(웹...
 

Recently uploaded

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 

Recently uploaded (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 

(자마린폼즈,Xamarin.Forms)ListView 데이터바인딩 실습_자마린기초교육,자마린 Data Binding 실습,자마린교육추천

  • 1. www.topcredu.co.kr 작성자 : 이종철 4.7.5 Xamarin.Forms ListView 데이터 바인딩  Model, ViewModel을 간단히 만들고 ViewModel을 ListView에 바인딩하는 간단한 예제를 작 성해 보자.  사원의 사번과 이름을 입력하면 아래쪽 ListView에 바인딩되서 데이터가 뿌려지는 간단한 예 제로 실행화면은 다음과 같다.
  • 3. namespace DataBindingTest { class Emp { public string Empno { get; set; } public string Ename { get; set; } public bool IsChecked { get; set; } } }  EmpViewModel.cs using System.Collections.ObjectModel; namespace DataBindingTest { class EmpViewModel { // Collection의 변화(Add/Delete)를 자동으로 감지하여 UI화면을 자동갱신 // ObservableCollection은 INotyfyChanged 인터페이스를 구현했다. // ListView를 자동으로 업데이트 하기위해 ObservableCollection을 사용. private ObservableCollection<Emp> emps = new ObservableCollection<Emp>(); public ObservableCollection<Emp> Emps { get { return emps; } set { emps = value; } } public EmpViewModel() { Emps = new ObservableCollection<Emp>(); } }
  • 4. }  MainPage.xaml <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:DataBindingTest" x:Class="DataBindingTest.MainPage"> <Grid HorizontalOptions="Center"> <Grid.RowDefinitions> <RowDefinition Height="40"/> <RowDefinition Height="40"/> <RowDefinition Height="40"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="40"/> <ColumnDefinition Width="100"/> <ColumnDefinition Width="40"/> <ColumnDefinition Width="100"/> </Grid.ColumnDefinitions> <Label Text="사번" Grid.Row="0" Grid.Column="0" VerticalOptions="Center"/> <Entry x:Name="txtEmpno" Grid.Row="0" Grid.Column="1" VerticalOptions="Center"/> <Label Text="이름" Grid.Row="0" Grid.Column="2" VerticalOptions="Center"/> <Entry x:Name="txtEname" Grid.Row="0" Grid.Column="3" VerticalOptions="Center"/> <Button x:Name="btnSave" Text="저장" Grid.Row="1" Grid.ColumnSpan="4" VerticalOptions="Center" Clicked="btnSave_Click"/> <ListView x:Name="listView" Grid.Row="3" Grid.ColumnSpan="4" VerticalOptions="Center"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View>
  • 5. <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <Label Grid.Column="0" Text="{Binding Empno}"></Label> <Label Grid.Column="1" Text="{Binding Ename}"></Label> <Switch Grid.Column="2" IsToggled="{Binding IsChecked}"></Switch> </Grid> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </Grid> </ContentPage>  MainPage.xaml.cs using System; using Xamarin.Forms; namespace DataBindingTest { public partial class MainPage : ContentPage { EmpViewModel viewModel = new EmpViewModel(); public MainPage() { InitializeComponent(); listView.ItemsSource = viewModel.Emps; //BindingContext = viewModel; } private void btnSave_Click(object sender, EventArgs e) { viewModel.Emps.Add(new Emp() { Empno = txtEmpno.Text, Ename =txtEname.Text,
  • 6. IsChecked = false}); txtEmpno.Text = ""; txtEname.Text = ""; } } }