
In the documentation (http://www.telerik.com/help/silverlight/gridview-sorting-programmatic.html), it shows this:
AutoGenerateColumns="False">
<telerik:RadGridView.SortDescriptors>
<telerik:SortDescriptor Member="Title"
SortDirection="Ascending" />
</telerik:RadGridView.SortDescriptors>
...
</telerik:RadGridView>
However, Member is not a property on SortDescriptor.
I tried this instead:
<telerik:ColumnSortDescriptor SortDirection="Ascending"
Column="{Binding ElementName=nextContactColumn}">
</telerik:ColumnSortDescriptor>
And got the error: Object reference not set to an instance of an object.
How do I in XAML tell the RadGridView to sort by a column
10 Answers, 1 is accepted
Column descriptors can only be added in code-behind.
Kind regards,
Milan
the Telerik team

can you then please remove it in the XAML example
Telerik\RadControls for WPF Q3 2011\Demos\Examples\GridView\Sorting\Example.xaml?
When will SortColumnDescriptors work in XAML as well?
Regards,
Hermann
Defining ColumnSortDescriptor in xaml is not supported. So, you can use the approach illustrated in the example you mentioned. Do you have any difficulties with it ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

actually using the XAML snippet from
Telerik\RadControls for WPF Q3 2011\Demos\Examples\GridView\Sorting\Example.xaml
works quite well,
<
telerik:RadGridView
Name
=
"radGridView5"
ItemsSource
=
"{Binding IncomingOrders}"
ShowInsertRow
=
"False"
AutoGenerateColumns
=
"False"
AlternationCount
=
"2"
IsReadOnly
=
"True"
SelectionMode
=
"Single"
>
<
telerik:RadGridView.SortDescriptors
>
<
telerik:ColumnSortDescriptor
Column
=
"{Binding Columns\[radGridView5.Priority.Shortcut\], ElementName=radGridView5}"
SortDirection
=
"Ascending"
/>
</
telerik:RadGridView.SortDescriptors
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Priority.Shortcut}"
Header
=
"Priorität"
UniqueName
=
"radGridView5.Priority.Shortcut"
/>
...
the column gets sorted
but when I serialize the whole grid using PersistenceFramework's PersistenceManager.Save()
as shown in example
Telerik\RadControls for WPF Q3 2011\Demos\Examples\PersistenceFramework\GridViewCustomSerialization
Save() fails in GridViewCustomPropertyProvider.ProvideValue()
foreach
(ColumnSortDescriptor descriptor
in
gridView.SortDescriptors)
{
proxies.Add(
new
SortDescriptorProxy()
{
ColumnUniqueName = descriptor.Column.UniqueName,
SortDirection = descriptor.SortDirection,
});
}
So, what has to be done to make it work?
Kind regards,
Hermann
I have tried to reproduce the issue you reported, but unfortunately without any success. Could you take a look at the sample attached to verify whether you can get the same exception on it ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

I have figured out why my source was not working.
There are several traps in the code - and my understanding of it
and maybe someone else can take advantage of this posting and save time to do more funny stuff.
Note: This is for WPF Q3 2011
- Order is not important. In the Telerik example (the zipped file above), the XAML sortdescriptor definition comes after the columns definition, but it works also with sortdescriptor def before columns def (- the more natural way for me)
- Telerik example uses a backslash as -kind of- string terminator for the ColumnSortDescriptor Column binding. This is a trap because it allows several possible ways to see it
(a) the "\" is a special character to allow parsing the square brackets within the xml statement
(so, ...ColumnSortDescriptor Column="{Binding Columns[\Value\], ... might be interpreted as
'\]' to allow a special character like
'\n' or '\{' whereas the first '[\' might be just a typo...
(I used \[Value\] in my xaml and it worked!)
(b) the "\" is part of a binding path, so the binding is related to the DataContext
and [\Value\] would mean:
bind to the property starting at datacontext's root
and then use the Value property.
Btw - if you omit all '\' it will work as well.
(c) The last sentence of (b) is not correct:
If you want to persist your gridview's layout, you have to add UniqeName as tagname
for the PersistenceManager.
But if you give the column a unique name, the previously working binding of the
ColumnSortDescriptor fails.
ColumnSortDescriptor's Column property becomes now null.
The reason for this is, that the definition of the ColumnsSortDescriptor has to be changed to
ColumnSortDescriptor Column="{Binding Columns[your_columns_unique_name]
or [\your_columns_unique_name\] (with or without backslash)
... yes, I know, this is all by design ...
but changing the ColumnsSortDescriptors Column binding path depending on a
property not related to binding at all in the GridViewDataColumn still looks like a bug for me.
... and - as always - this behaviour is undocumented...
Regards,
Hermann

<
telerik:RadGridView
ItemsSource
=
"{Binding Clausulas}"
SelectedItem
=
"{Binding SelectedClausula}"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding NumeroClausula}"
Header
=
"Número"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Texto}"
Header
=
"Claúsula"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding NumeroObligaciones}"
Header
=
"Obligaciones"
TextAlignment
=
"Right"
/>
</
telerik:RadGridView.Columns
>
<
telerik:RadGridView.SortDescriptors
>
<
telerik:SortDescriptor
Member
=
"NumeroClausula"
SortDirection
=
"Ascending"
/>
</
telerik:RadGridView.SortDescriptors
>
</
telerik:RadGridView
>
Thank you for sharing your thoughts and knowledge on the issue, it could be quite helpful for the community.
Considering the documentation, we will do our best to include some on the topic in one of our next updates of the online help.
We do appreciate your feedback.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Indeed, the ColumnSortDescriptor and SortDescriptor are simply two implementations of the ISortDescriptor interface and are not interchangeable.
As I could not infer from your last reply, could you please specify whether you're still experiencing an issue with the PersistenceManager and you need assistance or if you managed to resolve it?
I look forward to your reply.
Regards,
Dilyan Traykov
Progress Telerik