Note that there are some explanatory texts on larger screens.

plurals
  1. POSortDescription bound to an explicit interface implementation
    primarykey
    data
    text
    <p>I have an interface </p> <pre><code>public interface IProperty { string Name { get; } } </code></pre> <p>and an explicit implementation of it</p> <pre><code>public class Parameter : IProperty { private readonly string m_name; public Parameter(string name) { m_name = name; } string IProperty.Name { get { return m_name; } } } </code></pre> <p>I have a <strong>DataGrid</strong> that is showing an <strong>ObservableCollection&lt;IProperty&gt;</strong>. The only column, namely <strong>DataGridTextColumn</strong> is sorting the rows by virtue of the property <strong>SortMemberPath="(this:IProperty.Name)"</strong> (I got the idea of binding to explicit member implementations from <a href="http://social.msdn.microsoft.com/forums/en-US/wpf/thread/164727ec-c4f6-4277-a78e-6eacaf2bbf28" rel="nofollow">this forum thread</a>). </p> <p>So the problem is: <strong>How to have default rows sorting</strong>? I tried to do this in the window constructor:</p> <pre><code>var sortDescription = new SortDescription("(this:IProperty.Name)", ListSortDirection.Ascending); m_dataGrid.Items.SortDescriptions.Add(sortDescription); </code></pre> <p>with <em>almost</em> no luck. The effect is:</p> <ul> <li>The rows are sorted in some unspecified order</li> <li>I get lots of errors in the Visual Studio Output window:<br> System.Windows.Data Error: 39 : BindingExpression path error: '(this:IProperty.Name)' property not found on 'object' ''Parameter' (HashCode=25584554)'. null</li> <li>And the most interesting: when I apply any filtering (CollectionView.Filter) after collection is viewed - rows magically start being sorted correctly!</li> </ul> <p>Does anybody have an idea why the rows are not being sorted correctly from the very beginning?<br> If it matters I'm targeting .NET Framework v3.5</p>
    singulars
    1. This table or related slice is empty.
    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