开发者

How to bind array to Data template - List Box

I am currently parsing an HTML to produce an array shown below in a listbox

How to bind array to Data template - List Box

I am outputing each object in the array to a textbox like so

//first line
flight1.Text = node[0][2];
origin1.Text = node[0][3];
status1.Text = node[0][7];
time1.Text = node[0][6];

//second line

textBlock1.Text = node[1][3];
textBlock2.Text = node[1][3];
textBlock4.Text = node[1][7];
textBlock3.Text = node[1][6];

Thi开发者_如何转开发s is the outcome

How to bind array to Data template - List Box

AS you can image this is fairly grueling work and probably not the best way to do it.

Is there anyway to Bind each section on the array eg.. all flight names to a listbox in a data template so it would automatically list all the flight times and all the flight times etc..

Something like this for the XAML

<ListBox Margin="6,6,-12,0" Name="listBox1">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,17" Width="432" Height="Auto">

                            <TextBlock Text="{Binding FlightNumber}" Foreground="#FF4BCCF5" FontSize="24" />
                            <TextBlock Text="{Binding Origin}" TextWrapping="Wrap" FontSize="22" Foreground="#FF969696" />
                            <TextBlock Text="{Binding Time}" TextWrapping="Wrap" FontSize="20" Foreground="#FF05C16C" />
                            <TextBlock Text="{Binding Status}" TextWrapping="Wrap" FontSize="20" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>


I'm not sure what you would like to achieve. But in general I would suggest to do the following steps:

  1. Parse the HTML
  2. Put each line in FlightInformation-Class (with properties like you have in your XAML-example)
  3. Put all the FlightInformation-Objects in an ObservableCollection
  4. Apply a DataTemplate to your ItemsControl
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜