2011-08-05 67 views
1

我有一個字符串數組,我需要將它的值填充到列表框。但是值不在列表框中。這裏是我的代碼如何從字符串數組中填充值列表框

XAML

'<ListBox Name="listBox_1" Background="White" Margin="3,131,0,0"> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <Border BorderThickness="0,1,0,0" BorderBrush="#FFC1BCBC" Width="480"> 
         <Grid Height="80"> 
          <TextBlock Name="list" 
             Text="{Binding Path=Names}" 
             FontSize="36" 
             TextWrapping="Wrap" 
             Foreground="Black" FontWeight="Normal"/> 

         </Grid> 
        </Border> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox>' 

 'public class Names 
{ 
    //Model Class to hold Category details 

    public string Title { get; set; } 
    public string[] Names { get; set; } 
    public string[] Value { get; set; } 
}' 

xaml.cs

 'protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
    { 
     base.OnNavigatedTo(e); 

     string[] name = ((Application.Current as App).obj_category.Names); 
      listBox_1.ItemsSource=name; 



    }' 

我沒有得到顯示在列表中的名稱box.but我得到的邊界也就是說,如果字符串包含3個名字,我有三個空白行。爲什麼它中的文本沒有顯示?是否有人能幫助我。

回答

2

DataContextListBox在每個DataTemplatestring[]類型和DataContext的是string不具有的特性Name

更改Text="{Binding Path=Name}"Text="{Binding}"

+0

@mark謝謝你標記它現在的工作。 – Sujiz