실행된모습

image

 

시작(프로젝트 만들기)~

image
Person.cs는 바인딩할 리스트를반환한다.

바인딩용 리스트 만들기

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace TestWpfApplication
{


    public class Person
    {

        public Person()
        {

        }

        public Person(string name, int age)
        {
            this.Name = name;
            this.Age = age;
        }

        public string Name
        {
            set;
            get;
        }

        public int Age
        {
            set;
            get;
        }

        public static List<Person> GetPerson()
        {
            List<Person> p = new List<Person>();
            p.Add(new Person("kojaedoo", 19));
            p.Add(new Person("kojaeasdfdoo", 29));
            p.Add(new Person("1kafojaedoo", 13));
            p.Add(new Person("kojaasdfedoo", 49));
            p.Add(new Person("kojaedadfoo", 15));
            p.Add(new Person("kojaaaeadfdoo", 39));
            p.Add(new Person("kojafasdfedoo", 49));
            p.Add(new Person("kojaedofffo", 89));
            p.Add(new Person("kojaedo1234o", 79));
            return p;
        }
    }
}

GetPerson() 으로 리스트를 돌려받을꺼임

바인딩 처리

MainWindow.xaml
리스트박스에 ItemsSource를 ItemsSource=”{Binding}” 이라고 지정한다.

image

그럼 Blend에서 보면

image

이렇게 바인딩된 표시로 나타난다.

이제 아이템리스트 템플릿을  지정!

image

리스트박스에 마우스 오른쪽을 대고 Edit Generated Items를 클릭한다.

image

클릭하면

image

이런창이 나타난다 확인 누르고 계속 ㄱㄱ

코드상으로 템플릿이 추가되었다

image

코드도 ItemTemplate 를 사용하게 변경되어져 있다.

image

위와같이 추가되어져 있다.

ItemTemplate변경하기

위에서 확인 눌러도 암것도 없다

여기에 출력할 Name과 Age를 표시해주자

image

TextBlock을 끌어와서 대충디쟌
image

요렇게 앞에는 Name 뒤에는 Age 표시할꺼다

텍스트블록을 클릭한다음

image

Text의 바인딩을 지정해주자

 

image 
Data Context로 맞춘다음

image
Name이라고 지정해따 Age도 똑같이 ㄱㄱ

 

비하인드 코드에서 바인딩해주기

image

F5

image

ItemsPanelTemplate을 변경하면

image
아래와 같이 가로로도 출력되게 할수 있다 ㅋ

image

+ Recent posts