So I am writing my first WinRt app in VS2013 in vb.net and I cannot figure out how to bind data to my list view. I can bind basic data but I cannot bind to multiple elements.
Here is my code that is working with basic binding
Dim itemList = New List(Of String)()
Dim xmlDoc As XDocument = XDocument.Load("Survey.xml")
Dim query = From WOACTWF In xmlDoc.Descendants("WOACTWF")
Select wono = WOACTWF.Elements("WAWONO").Value, act = WOACTWF.Elements("WAACT").Value
For Each item In query
itemList.Add(item.wono + " " + item.act)
Next
lvSurvey.ItemsSource = itemList
Here is my XAML Code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Content="Button" Click="Button_Click_1" />
<TextBlock Text="Survey" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1"
IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,10"/>
</Grid>
<ListView x:Name="lvSurvey" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="50" Width="400">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="txtWONO" Text="{Binding}" Width="400" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
But i want the XAML to look like this:
<ListView x:Name="lvSurvey" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="50" Width="400">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical">
<TextBlock x:Name="txtWONO" Text="{Binding WAWONO}" Width="400" />
<TextBlock x:Name="txtJobCat" Text="{Binding HXJOBCAT}" Width="400" />
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I tried to convert some C# examples but they don't work: (After the first apostrophe is expects end of statement)
Dim xmlDoc As XDocument = XDocument.Load("Survey.xml")
Dim data= From query In xmlDoc.Descendants("WOACTWF")New XmlSurvey() With { _
Key .WAWONO = DirectCast(query.Element("WAWONO"), String), _
Key .HXJOBCAT = DirectCast(query.Element("HXJOBCAT"), String) _
}
lvSurvey.ItemsSource = Data
This is the class i wrote:
Public Class XMLSurvey
Private m_WAWONO As String
Public Property WAWONO() As String
Get
Return m_WAWONO
End Get
Set(value As String)
m_WAWONO = value
End Set
End Property
Private m_HXJOBCAT As String
Public Property HXJOBCAT() As String
Get
Return m_HXJOBCAT
End Get
Set(value As String)
m_HXJOBCAT = value
End Set
End Property
End Class
Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<AS400>
<WOACTWF>
<WACOMP>1</WACOMP>
<WAWONO>005111</WAWONO>
<WABLD> 1</WABLD>
<WAFLOOR>1 </WAFLOOR>
<WAROOM> 1</WAROOM>
<WAACT>INSTL</WAACT>
<WASTAS>OPEN </WASTAS>
<WASCHDT>0</WASCHDT>
<WASTRDT>0</WASTRDT>
<HXWONO>005111</HXWONO>
<HXWOSTAS>HOLD </HXWOSTAS>
<HXNAME>84 STREET </HXNAME>
<HXADR1>1 EAST 84 STREET </HXADR1>
<HXCITY>NEW YORK </HXCITY>
<HXSTATE>NY</HXSTATE>
<HXJOBCAT>NEW </HXJOBCAT>
<HXMUSTDT>0</HXMUSTDT>
</WOACTWF>
<WOACTWF>
<WACOMP>1</WACOMP>
<WAWONO>005115</WAWONO>
<WABLD> 1</WABLD>
<WAFLOOR>1 </WAFLOOR>
<WAROOM> 1</WAROOM>
<WAACT>INSTL</WAACT>
<WASTAS>OPEN </WASTAS>
<WASCHDT>0</WASCHDT>
<WASTRDT>0</WASTRDT>
<HXWONO>005115</HXWONO>
<HXWOSTAS>HOLD </HXWOSTAS>
<HXNAME>SCARED HEART </HXNAME>
<HXADR1>1 FATHER DRIVE </HXADR1>
<HXCITY>YONKERS </HXCITY>
<HXSTATE>NY</HXSTATE>
<HXJOBCAT>NEW </HXJOBCAT>
<HXMUSTDT>0</HXMUSTDT>
</WOACTWF>
No comments:
Post a Comment