2012-11-10 4 views
0

Windows Store App 프로젝트가 있습니다.클래스 필드를 ItemTemplate에 바인딩하는 방법

아이템 페이지를 만들었습니다. 그것은 모두 기본값이며 요소를 제대로 표시 할 수 있도록 GridView에 사용자 정의 클래스를 바인딩하고 싶습니다.

GridView의 ItemTemplate이 Standard250x250ItemTemplate으로 설정됩니다. 그 템플릿을 사용하여 내 사용자 정의 요소를 표시하는 방법을 알려드립니다. 내가 어떻게 할 수 있니? 내 ItemTemplate을 직접 만들어야합니까? 나는 기존의 것을 사용하고 싶다.

Btw 내 컬렉션에 itemGridView.ItemsSource을 설정하고 있습니다. 그게 GridView에 무엇을 표시 할 것인가를 말하는 올바른 방법입니까?

답변

0

당신은 내가 한 예는이

Grid SegmentsGrid = new Grid(); 
GridRuntimeTemplate AirlinesTemplate = new GridRuntimeTemplate(); 
AirlinesTemplate.ID = "AirlinesTemplate1"; 
AirlinesTemplate.ControlID = "AirlinesComboBox1"; 
AirlinesTemplate.Template = new Obout.Grid.RuntimeTemplate(); 
AirlinesTemplate.Template.CreateTemplate += new Obout.Grid.GridRuntimeTemplateEventHandler(CreateAirlinesTemplate); 

GridRuntimeTemplate ClassesTemplate = new GridRuntimeTemplate(); 
ClassesTemplate.ID = "ClassesTemplate1"; 
ClassesTemplate.ControlID = "ClassesComboBox1"; 
ClassesTemplate.Template = new Obout.Grid.RuntimeTemplate(); 
ClassesTemplate.Template.CreateTemplate +=new Obout.Grid.GridRuntimeTemplateEventHandler(CreateClassesTemplate); 

SegmentsGrid.Templates.Add(ClassesTemplate); 
SegmentsGrid.Templates.Add(AirlinesTemplate); 

    public void CreateAirlinesTemplate(Object sender, Obout.Grid.GridRuntimeTemplateEventArgs e) 
    { 
     PlaceHolder ph1 = new PlaceHolder(); 
     e.Container.Controls.Add(ph1); 


     AirlinesComboBox.ID = "AirlinesComboBox1"; 
     AirlinesComboBox.Width = Unit.Percentage(100); 
     AirlinesComboBox.Height = Unit.Pixel(200); 
     AirlinesComboBox.DataTextField = "Airline_Long_Name"; 
     AirlinesComboBox.DataValueField = "Airline_Long_Name"; 
     AirlinesComboBox.EmptyText = "Select Airline ..."; 
     AirlinesComboBox.EnableLoadOnDemand = true; 
     AirlinesComboBox.LoadingItems += AirlinesComboBox1_LoadingItems; 

     ph1.Controls.Add(AirlinesComboBox); 
    } 

protected void AirlinesComboBox1_LoadingItems(object sender, ComboBoxLoadingItemsEventArgs e) 
    { 
     // Getting the countries 
     DataTable data = GetAirlines(e.Text); 

     // Looping through the items and adding them to the "Items" collection of the ComboBox 
     for (int i = 0; i < data.Rows.Count; i++) 
     { 
      (sender as ComboBox).Items.Add(new ComboBoxItem(data.Rows[i]["Airline_Long_Name"].ToString(), data.Rows[i]["Airline_Long_Name"].ToString())); 
     } 

     e.ItemsLoadedCount = data.Rows.Count; 
     e.ItemsCount = data.Rows.Count; 
    } 


    protected void ClassesComboBox1_LoadingItems(object sender, ComboBoxLoadingItemsEventArgs e) 
    { 
     // Getting the countries 
     DataTable data = GetClasses(e.Text); 

     // Looping through the items and adding them to the "Items" collection of the ComboBox 
     for (int i = 0; i < data.Rows.Count; i++) 
     { 
      (sender as ComboBox).Items.Add(new ComboBoxItem(data.Rows[i]["Class_Name"].ToString(), data.Rows[i]["Class_Name"].ToString())); 
     } 

     e.ItemsLoadedCount = data.Rows.Count; 
     e.ItemsCount = data.Rows.Count; 
    } 

    public void CreateClassesTemplate(Object sender, Obout.Grid.GridRuntimeTemplateEventArgs e) 
    { 
     PlaceHolder ph1 = new PlaceHolder(); 
     e.Container.Controls.Add(ph1); 


     ClassesComboBox.ID = "ClassesComboBox1"; 
     ClassesComboBox.Width = Unit.Percentage(100); 
     ClassesComboBox.Height = Unit.Pixel(200); 
     ClassesComboBox.DataTextField = "Class_Name"; 
     ClassesComboBox.DataValueField = "Class_Name"; 
     ClassesComboBox.EmptyText = "Select Flight Class ..."; 
     ClassesComboBox.EnableLoadOnDemand = true; 
     ClassesComboBox.LoadingItems += ClassesComboBox1_LoadingItems; 
     ph1.Controls.Add(ClassesComboBox); 
    } 
Obout 아약스 LIB를 사용하여 항목 템플릿 여기

를 작성해야

관련 문제