I have a grid view code below which have divided into 3 column. But i have a problem with the code is that. When multiple data is retrieved
Quickhorn's answer is mostly right. The issue is you're creating one big grid instead of a row for each item in the list. Here's a simplified example of your code which uses a model object and databinding instead.
This way you can style everything in the xaml easily and it makes things much simpler.
Code Behind: MainPage.xaml.cs
public partial class MainPage : PhoneApplicationPage
{
private ObservableCollection _schedules;
public MainPage()
{
InitializeComponent();
string[] timeSplit = new string[] { "One1", "Two2", "Three3" };
string[] titleSplit = new string[] { "Title1", "Title2", "Title3" };
string[] categorySplit = new string[] { "Priority", "Favourite", "Another" };
_schedules = new ObservableCollection();
for ( int i = 0; i < timeSplit.Length; i++ )
{
_schedules.Add( CreateSchedule( timeSplit[i], titleSplit[i], categorySplit[i] ) );
}
scheduleListBox.ItemsSource = _schedules;
}
private Schedule CreateSchedule( string time, string title, string category )
{
Schedule schedule = new Schedule
{
Time = time,
Title = title,
Category = category
};
if ( category == "Priority" )
{
schedule.ImageSource = "/AlarmClock;component/Images/exclamination_mark.png";
}
else if ( category == "Favourite" )
{
schedule.ImageSource = "/AlarmClock;component/Images/star_full.png";
}
return schedule;
}
}
public class Schedule
{
public string Time { get; set; }
public string Title { get; set; }
public string Category { get; set; }
public string ImageSource { get; set; }
}
MainPage.xaml