Reputation: 63
I want to bind the data in to list, the data can be parsed through xml and stored in local variables.
Next I want to bind these data in to list and stored in isolated storage. Please help me out.
if (e.Result != null)
{
string serviceDate, name, taskname;
XDocument doc;
doc = XDocument.Parse(e.Result);
foreach (var absentDate in doc.Element("Classworks").Descendants("Classwork"))
{
serviceDate = absentDate.Element("ClassworkDate").Value.ToString();
name = absentDate.Element("Subject").Value.ToString();
taskname = absentDate.Element("Task").Value.ToString();
}
}
else
{
}
Upvotes: 1
Views: 61
Reputation: 89285
These are the steps you need to perform approximately :
MyModel
. If MyModel
property values is not static (can be changed at runtime), you may also need to implement INotifyPropertyChanged
in the model.ObservableCollectoin<MyModel>
, say it MyItemsSource
LongListSelector
or similar user control that capable of displaying multiple data on the Page. Bind the control's ItemsSource
to MyItemsSource
propertyDataContext
properly.MyItemsSource
in code, you can do this in foreach
part shown in question.MyItesSource
property. Just save it.Step 1
public class MyModel
{
public string ClassworkDate { get; set; }
public string Subject { get; set; }
public string Task { get; set; }
}
Step 2
public ObservableCollection<MyModel> MyItemsSource { get; set; }
Step 4
public MainPage()
{
InitializeComponent();
MyItemsSource = new ObservableCollection<MyModel>();
this.DataContext = this;
}
Step 5
foreach (var absentDate in doc.Element("Classworks").Descendants("Classwork"))
{
serviceDate = absentDate.Element("ClassworkDate").Value.ToString();
name = absentDate.Element("Subject").Value.ToString();
taskname = absentDate.Element("Task").Value.ToString();
var newModel = new MyModel{
ClassworkDate = serviceDate,
Subject = name,
Task = taskname
};
MyItemsSource.Add(newModel);
}
Above are codes related to logic in steps I explained before. With those codes setup, your data is ready to be bound. Note that in this example I didn't implement INotifyPropertyChanged
for brevity.
Upvotes: 1