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:
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
(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
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;
}
Replies
Know the answer? Post it — somebody with the same question will find it here.