开发者

how to populate values to list box from a string array

I have a string array and i need to populate its value to a list box.but the values are not get in the list box. here is my code

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>'

class

        '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;



    }'

i didnt get the names displayed in the list box.but i got the border lines that is, if the string contain 3 names i got three blank rows.why the text in it doesnot display?could any one help me .


DataContext in your ListBox is of type string[] and DataContext in each DataTemplate is a string which doesn't have a property Name.

Change Text="{Binding Path=Name}" to Text="{Binding}".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜