[Q] WP7 - ListBox w/template ADD Item??
Hi there,
Well, here is my situation and hopefully someone could shed some light on this annoying dilemma...
I'm pretty sure the solution is quite easy ,but so far I cannot find one.
I have a ListBox with a data template.
Now, I want to add some items (pretty easy, isn't it?
But...I always get the same data in every row...
Here is my code
Code:
Option Strict On
Option Explicit On
Partial Public Class MainPage
Inherits PhoneApplicationPage
Dim DataSelected As New Class_DS
' Constructor
Public Sub New()
InitializeComponent()
End Sub
Public Class Class_DS
Public Property DS_Distance() As Integer
Public Property DS_Value() As String
Public Property DS_Angle() As String
End Class
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
For x As Integer = 1 To 4
DataSelected.DS_Distance = x
DataSelected.DS_Value = (x + 2).ToString
DataSelected.DS_Angle = (x + 3).ToString
Me.ListBox_DS.Items.Add(DataSelected)
Next x
End Sub
End Class
Quite simple, but doesn't work as expected!
Just in case, here goes the XAML
Code:
<DataTemplate x:Key="Template_DS">
<StackPanel>
<Border Width="450" CornerRadius="15">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF032E45" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Grid>
<TextBlock x:Name="TextBlock_DS_Distance" Text="{Binding DS_Distance}" VerticalAlignment="Top" d:LayoutOverrides="Width" FontSize="26.667" Margin="4,15,4,0"/>
<TextBlock x:Name="TextBlock_DS_Value" Text="{Binding DS_Value}" Margin="4,50,4,0" d:LayoutOverrides="Width" FontSize="26.667" VerticalAlignment="Top" Foreground="#FFE6FF05"/>
<TextBlock x:Name="TextBlock_DS_Angle" Text="{Binding DS_Angle}" d:LayoutOverrides="Width" FontSize="21.333" Margin="4,85,4,0" VerticalAlignment="Top" Foreground="White"/>
</Grid>
</Border>
</StackPanel>
</DataTemplate>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="ListBox_DS" ItemTemplate="{StaticResource Template_DS}" Background="{x:Null}" Margin="3,111,3,0" BorderBrush="Blue" BorderThickness="8" Height="490" VerticalAlignment="Top" />
<Button Content="Button" Height="87" HorizontalAlignment="Left" Margin="9,18,0,0" Name="Button1" VerticalAlignment="Top" Width="441" />
</Grid>
What I get is 4 rows with exactly the same data...
Row 1
4
6
7
Row 2
4
6
7....
What I expect is to get this
Row 1
1
3
4
Row 2
2
4
5
Don't have a clue where the issue is, perhaps with the class template or else...
Amybe I'm missing some sort of method??
Any help is greatly appreciated!