Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF DataGrid: Get column binding property for filtering
    primarykey
    data
    text
    <p>I am trying to develop a filtering functionality for WPF <code>DataGrid</code> (from the WPF Toolkit). I want a user to right-click any cell and select <code>Filter</code> from its <code>CcontextMenu</code>, and then the grid should be filtered by the cell's value.</p> <p>I am trying the M-V-VM pattern. My windows's datacontext is <code>MainWindowViewModel</code> which has a property <code>Transactions</code>. This property returns <code>ObservableCollection&lt;TransactionViewModel&gt;</code>, and the data grid uses this collection as its items source. So basically each row is bounded to <code>TransactionViewModel</code> (as you can guess, this grid lists transactions). <code>MainWindowsViewModel</code> has <code>ICollectionView</code> which is used for filtering and tracking the currently selected row. The <code>DataGrid</code> has its property <code>IsSynchronizedWithCurrentItem</code> set to "true", so <code>myCollectionView.CurrentItem</code> gives me the currently selected <code>TransactionViewModel</code>.</p> <p>The only thing I still need to know is by which column I need to filter. This depends on where the user clicked the context menu. So I am trying to pass this information using <code>CommandProperty</code> of the context menu item. And here I have a real problem. I tried this:</p> <pre><code>CommandParameter="{Binding Column.Binding.Path.Path, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type tk:DataGridCell}}}" /&gt; </code></pre> <p>This is really ugly, but this works for <code>DataGridTextColumn</code>s. Unfortunately, I have also <code>DataGridTemplateColumn</code>s, and they don't work (the path is different there, because I need to reach the actual cell template)... </p> <p>So how can I implement this functionality? Perhaps the whole way is wrong? I didn't find any valuable example on that. The only thing I found is the WPF <code>DataGrid</code> autofilter implementation on the Codeproject which doesn't work at all for some reason...</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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