I try to use data binding to add to ListBox in WP7, using C#. But it seems not working and I totally don't know why. Just only row's border is drawn and text's content doesn't display.
Here is a class i want to add to
public class ResultTemplate
{
public string Mealname;
public string CanteenID;
public DateTime Date;
}
public class View
{
List<ResultTemplate> result;
//....
void Load()
{
this.listbox.ItemSource = result;
}
}
My XAML code :
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="searchlist" ItemsSource="{Binding}" SelectionChanged="searchlist_SelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" BorderBrush="#FF807C7C" Width="500" HorizontalAlignment="Center">
<StackPanel MinHeight="60" Width="450" HorizontalAlignment="Left" Margin="25,0,0,0">
<StackPanel Orientation="Horizontal">
<TextBlock Name="textblock1" Text="{Binding Mealname}" HorizontalAlignment="Left" TextWrapping="Wrap" FontSize="25" Width="385" />
<!--<Image Source="{Binding Image}" Stretch="None" Margin="10,0,0,0" Height="50" Width="50"/>-->
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Name="textblock2" Text="{Binding CanteenID}" HorizontalAlignment="Left" Width="150" FontSize="20" Foreground="#FF004AFF"/>
<TextBlock Name="textblock3" Text="{Binding Date,StringFormat=dddd.dd/MM/yyyy}" HorizontalAlignment="Left" FontSize="20" Foreground="#FF00AB00"/>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>