views:

67

answers:

3

Hej,

I'm trying to make som general functionality for my ListView, so that the content of a ListView can be exported to CSV directly.

I'm trying to achive this by getting the datacontext and analysing the ICollectionView for this. From here I have access to the all the objects from via ICollectionView via SourceCollection, in which I (for now) presume sorting/and filtering is respected.

The challange here is that I only want to output the columns that also are showed in the ListView.

When iterating my collection, is there a function where I can evluate if a property in a class (with notification suppoert) has a binding to it?

The esiest solution for now would be just to output all properties, but I'm not interested in this, since oid's are not fun to look at.

Thx in advanced.

/Ian

A: 

Why don't you just look at the DataTemplate and evaluate it including the binding inside?

eriawan
A: 

There's no easy way to do it... You can check the binding on the target side (dependency property), but not on the source side.

For what you're trying to do, you could loop through the columns of the ListView and check their DisplayMemberBinding, but it could be undefined (the cell content might be defined using the CellTemplate property instead).

Thomas Levesque
+1  A: 

I suggest you recognize that the ability to determine which data is being displayed is a business requirement. Thus, you should embody this requirement in your model. In other words, your model should clearly indicate which columns are visible - you shouldn't be trying to infer this from your existing properties, nor should you be examining your view.

There are a whole bunch of ways you could do this, but the key is to have this information on hand in your model.

HTH, Kent

Kent Boogaart