1

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 .

1 Answer 1

2

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}".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.