Bhaskar  Sharma

Bhaskar Sharma

  • NA
  • 2
  • 2.6k

Displaying Data in textblock in windows phone 7 application

Mar 12 2014 2:59 AM
I am building an application for windows phone 7 where i have a few data coming from the web service. Those fields are:

restaurant_name, street_address, location_name, country, phone_no, email_id


Now i will have multiple data with these fields. The data should be displayed together in one textblock and when the user swipes it the next data should be shown in another textblock and so on.

I tried it in the following way but was not able to do it. Moreover i donot know much about the swipe.

My xaml is:

<TextBlock Height="291" HorizontalAlignment="Left" Margin="16,399,0,0"
Name="restdata" Text="" VerticalAlignment="Top" Width="446" />


My code behind:



public class Rest
{
public string restaurant_name { get; set; }
public string street_address { get; set; }
public string location_name { get; set; }
public string country { get; set; }
public string phone_no { get; set; }
public string email_id { get; set; }
public string restaurant_image { get; set; }
public BitmapImage ImageBind { get; set; }
}

public const string RestXml = "Rest.xml";

public Rahm()
{
InitializeComponent();
LoadData();
}

private void LoadData()
{
bool isSuccess;
//try to load data from iso store
var doc = ReadXml(out isSuccess);

if (isSuccess) PopulateList(doc);

//if failed (data doesn't exists in iso store), download data from web service

else

{
RahmService.RahmSoapClient client = new RahmService.RahmSoapClient();
client.getRestaurantLocationAllCompleted += new EventHandler<RahmService.getRestaurantLocationAllCompletedEventArgs>
(client_getRestaurantLocationAllCompleted);
client.getRestaurantLocationAllAsync();
}
}

void client_getRestaurantLocationAllCompleted(object sender, RahmService.getRestaurantLocationAllCompletedEventArgs e)
{
var doc = XDocument.Parse(e.Result);
PopulateList(doc);
WriteXml(doc);
}

private void PopulateList(XDocument doc)
{
// List<Rest> restList = new List<Rest>();

foreach (var location in doc.Descendants("UserDetails"))

{
Rest data = new Rest();
data.restaurant_name = location.Element("restaurant_name").Value;
data.street_address = location.Element("street_address").Value;
data.location_name = location.Element("location_name").Value;
data.country = location.Element("country").Value;
data.phone_no = location.Element("phone_no").Value;
data.email_id = location.Element("email_id").Value;

restdata.Text = data.restaurant_name;
restdata.Text = data.street_address;
restdata.Text = data.location_name;
restdata.Text = data.country;
restdata.Text = data.email_id;
restdata.Text = data.phone_no;
// data.restaurant_image = location.Element("restaurant_image").Value;
// data.ImageBind = new BitmapImage(new Uri(@" http://restaurant.vzons.com/images/restaurants/"
// + data.restaurant_image, UriKind.Absolute));
}

}

private XDocument ReadXml(out bool isSuccess)
{
isSuccess = false;

var doc = new XDocument();

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())

{
try

{
if (store.FileExists(RestXml))

{
using (var sr = new StreamReader(new IsolatedStorageFileStream
(RestXml, FileMode.OpenOrCreate, store)))
{
doc = XDocument.Load(sr);
}

isSuccess = true;
}
}
catch (Exception ex) { }
}
return doc;
}


private bool WriteXml(XDocument document)
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())

{
try

{
using (var sw = new StreamWriter(new IsolatedStorageFileStream(RestXml, FileMode.Create, store)))
{
sw.Write(document.ToString());
}
}
catch (Exception ex) { return false; }
}
return true;
}