2015-09-17 63 views
0

我在这里为数据绑定挣扎Windows Phone 7.1。我有一个DataLoader类,其中一个OnservableCollectionItemList(自定义类)作为属性。因此,每个数据透视表项都有自己的项目列表。在这个DataLoader中,我从JSON加载数据JSON。到现在为止还挺好。将代码数据绑定到XAML数据透视表框

public ObservableCollection<ItemList> PivotItem { get; set; } 

在这里,我存放5 ItemList,一个与他对应的产品清单每个枢轴头。

但我的问题是,我想要将这些数据绑定到每个PivotItem中的ListBox的XAML。

<phone:Pivot Title="iMetrópolis" Loaded="Pivot_Loaded"> 
     <!--Elemento Pivot 1--> 
     <phone:PivotItem 
      x:Uid="PivotItem1" 
      Header="Todo" Margin="14,10,10,18"> 

      <ListBox x:Name="FirstListBox" ItemsSource="{Binding Items}"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Margin="0,0,0,17" Width="432" Height="78"> 
         // I want to add textboxes binding my data 
         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 
     </phone:PivotItem> 
     . 
     . 
     . 

感谢您的答复!

回答

1

以下是我认为你需要数据绑定

 <ListBox x:Name="listBox1"> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Height="auto" > 
         <TextBlock Text="{Binding PON}" /> 
         <TextBlock Text="{Binding PIN}" /> 

        </StackPanel> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 

和一类做的,一个例子是

public class ListObject 
    { 
     public string PON { get; set; } 
     public string PIN { get; set; } 
    } 

和JSON结合实际数据

 dynamic json = JsonConvert.DeserializeObject(jsondata); 

    var questions = new List<ListObject>(); 
     foreach (var abc in json["jsonarray"]) 
       { 
    var listOfItems = new ListObject(); 
listOfItems.PON= abc.object1; 
listOfItems.PIN= abc.object2; 
questions.Add(listOfQuestions); 

} 

    listBox1.ItemsSource = questions; 

我希望它可以帮助回复任何意见

+0

感谢您的回复!但是'ListBox'使用'ItemsSource'作为'ItemsSource',但是PON和PIN从其他来源获取不同于'questions'对象(?)内的内容的值。那么,我有(例如一个标题(字符串)列表,我想用它作为我的'ItemsSource',但我想显示每个字符串在PON'TextBox'。 –

+0

嗨,队友!我已经理解了整个绑定的事情,你的回复真的有用! –