Reputation: 1228
I have a small project that I think WPF would be perfect for, I don't however have that much time so I am looking for feasibility information and pointers. I am trying to display a large number of items from an XML document and from what I have read so far I believe it would be possible to:
Use the XML document as a dataSource.
Load each item from the XML into an object, which is then added to a collection. (Is it possible to bind the XML straight to the collection?)
Using the collection bind it to a view.
Each object in the view is displayed in a similar fashion to that of an HTML table. (Use a custom control in stackPanel vertically?)
There may be thousands of objects within the collection so need to be be able to display only 50/page with the ability to sort and search. (Using collectionView?)
I have seen similar scenarios and examples on the web but most are watered down, I don't want to start this and then hit a brick wall when I could create a web based solution.
If anyone could tell me if it's possible, point me in the right direction or highlight any potential problem areas it would be appreciated.
Thanks.
Upvotes: 1
Views: 949
Reputation: 12934
Consider this sample xml file:
<Employees>
<Employee ID="101">
<Name>Ram</Name>
<Salary>5000</Salary>
</Employee>
<Employee ID="102">
<Name>Siva</Name>
<Salary>7000</Salary>
...
</Employee>
You can load the data from an xml file like this:
XDocument doc = XDocument.Load(yourFilePath);
Then you can query it like this:
var filterQuery = from i in doc.Descendants("someNode")
where (float)i.Element("Salary") >= 6000.00
orderby (string)i.Element("Name")
select (string)i.Element("Name");
Create an ObservableCollection out of it
var filteredList = new ObservableCollection(filterQuery);
Bind this to your ListView or other Collection in xaml.
You can implement sorting and searching logics on the doc
and re-populate your ObservableCollection anytime and the changes would be automatically reflected in the ListView.
Upvotes: 1