2013-03-15 81 views
0

我想制作一些带有文字的矩形。当你通过一个小组观察联络人时,人民中心的那个人。是否需要执行绑定的列表? Windows Phone 7

我在想,虽然我需要根据每个项目制作X个矩形,但是我不知道如何让它重复。

我能想到的唯一方法是使用一个列表,然后尝试获取带有文本的矩形。

我不确定是否可以像重复堆叠面板或重复网格一样。

回答

0

这真的取决于你想要做什么。

如果你有固定的项目的数量,你知道他们应该是什么样子设计时

那么你可以简单地在XAML添加ListBoxItem

  <ListBox> 
       <ListBox.Items> 
        <ListBoxItem> 
         <Border Background="Green" Width="70" Height="70"> 
          <Grid> 
           <Rectangle Width="50" Height="50" 
              Fill="Red" Margin="10" /> 
           <TextBlock Text="1" HorizontalAlignment="Center" 
                VerticalAlignment="Center" /> 
          </Grid> 
         </Border> 
        </ListBoxItem> 
        <ListBoxItem> 
         <Border Background="Blue" Width="70" Height="70"> 
          <Grid> 
           <Rectangle Width="50" Height="50" 
              Fill="Yellow" Margin="10" /> 
           <TextBlock Text="2" HorizontalAlignment="Center" 
              VerticalAlignment="Center" /> 
          </Grid> 
         </Border> 
        </ListBoxItem> 
       </ListBox.Items> 
      </ListBox> 

如果你不这样做知道有多少项目提前,并希望他们都有相同的外观

然后是的,绑定是唯一的出路

根据在UI用于数据绑定项的复杂性,可能要包裹在一个单独的(用户),该用户界面的逻辑控制,并用其作为DataTemplate中的项目:

  <ListBox ItemsSource={Binding TheItemsToBind}> 
       <ListBox.ItemTemplate> 
        <DateTemplate> 
         <mycontrols:MySpecializedControl 
          [...whatever it takes to bind to the data item...]/> 
        </DateTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 
0

本身的绑定列表不知道该元素在ListBox中的样子。您需要为每个项目定义DataTemplate(更多详细信息here)。

现在,由于您正在讨论在People Hub中完成的分组,因此您可以使用LongListSelector控件(教程herehere)。