The are couple of things why your code doesn't work:
- you are not setting Column for your TextBlocks - Grid.SetColumn()
- you are creating Grid, but you aren't adding it to to any StackPanel or ListBox which are visible on the screen
- I'm not sure what you have tried to achieve within foreach loop
- it is hard to tell what you 'logic for binding' does
In this case it is simpler to use a ListBox:
In XAML, in your Page:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox Name="myList">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding textFirst}" Grid.Column="0" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding textSecond}" Grid.Column="1" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding textThird}" Grid.Column="2" HorizontalAlignment="Right"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
In code behind - you just then declare ObservableCollection for items and set it as ItemsSource of ListBox. You need also to create a class with your data:
public class Data
{
public string textFirst { get; set; }
public string textSecond { get; set; }
public string textThird { get; set; }
}
public partial class MainPage : PhoneApplicationPage
{
ObservableCollection<Data> dataReceived = new ObservableCollection<Data>();
public MainPage()
{
InitializeComponent();
myList.ItemsSource = dataReceived;
// and to add data you do it like this:
dataReceived.Add(new Data() { textFirst = "First text", textSecond = "Second Text", textThird = "Third one" });
}
}