Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Two solutions for dynamic sorting ...</p> <ol> <li><p>GridView's ItemsSource is set to a <code>ICollectionView</code> or <code>ListCollectionView</code> with <code>SourceCollection</code> set as your own List and having a <code>SortDescription</code> where PropertyName can be specified as a string value... <a href="http://marlongrech.wordpress.com/2008/11/22/icollectionview-explained/" rel="nofollow noreferrer">http://marlongrech.wordpress.com/2008/11/22/icollectionview-explained/</a></p></li> <li><p>Dynamic LINQ with <code>MyList.AsQueryable().OrderBy(&lt;OrderByClause&gt;)</code> where order by clause can be created dynamically... <a href="https://stackoverflow.com/questions/307512/how-do-i-apply-orderby-on-an-iqueryable-using-a-string-column-name-within-a-gener">How do I apply OrderBy on an IQueryable using a string column name within a generic extension method?</a></p></li> </ol> <p>So when user clicks on the grid view column headers, you have to extract the property name that the column is representing and use any of the two above approaches. In option 2 you would have to set the ItemsSource after the collection is sorted.</p> <p>Any of the two approaches can be done in an Attached Behavior that works on GridViews in order to have a generic solution. </p> <pre><code>&lt;ListView myNameSpace:ListSortingBehavior.SortingSource="CollectionView" ... /&gt; &lt;!-- CollectionView SortDescriptions --&gt; </code></pre> <p>OR</p> <pre><code>&lt;ListView myNameSpace:ListSortingBehavior.SortingSource="Generic" ... /&gt; &lt;!-- AsQueryable LINQ --&gt; </code></pre> <p>All you have to worry about it if you use option1, then you would have to assume that the GridView.ItemsSource is always going to be an ICollectionView. In second approach the trade off is you would have to "set" the ItemsSource after sorting.</p> <p>I hope this helps...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload