This is a migrated thread and some comments may be shown as answers.

Problem specifying the Expression property of the GridViewExpressionColumn in Xaml ?

1 Answer 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 07 Jan 2013, 08:25 AM
Hi,

I am having difficulties in specifying the Expression property of the GridViewExpressionColumn in Xaml.
I have this column that I want to turn into a expression column :
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Attributes.[PERCEELID]}" Header="PerceelId" DataType="{x:Type sys:Int32}" />
First step, make ik a GridViewExpressionColumn :
<telerik:GridViewExpressionColumn UniqueName="Opp" Header="Oppervlakte (ha)" Expression="Attributes[&quot;PERCEELID&quot;]" />
So far so good, this still displays the same result as my original column (nothing calculated so far).
But as soon as I want to do something with this value, nothing is shown and I receive errors in the output window.
This is about the simplest expression I can think of (multiplying by 2) :
<telerik:GridViewExpressionColumn UniqueName="Opp" Header="Oppervlakte (ha)" Expression="Attributes[&quot;PERCEELID&quot;] * 2" />
The column stays empty and the outpunt window shows :

A first chance exception of type 'System.ArgumentException' occurred in System.ComponentModel.DataAnnotations.dll

A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll


I have tried to explicitely cast my value first before multiplying (Convert.ToInt32(Attributes[&quot;PERCEELID&quot;]) * 2); but no success.

If I do the same in code-behind, there is no problem :
    Expression<Func<Graphicdouble>> expression = g => (int)g.Attributes["PERCEELID"] * 2;
    var c = this.GevondenPercelenDataGrid.Columns["Opp"as GridViewExpressionColumn;
    c.Expression = expression;


The ToString() of this expression yields:

"g => Convert((Convert(g.Attributes.get_Item(\"PERCEELID\")) * 2))"

Using this string as value for "Expression" in the xaml is no solution either.





Can anyone give me some tips on building expressions in xaml ?



 





Kind regards,



















Martin



1 Answer, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 07 Jan 2013, 09:46 AM
Hi,

Since this expression involves an explicit cast from object to int, the only way would be to specify it through code-behind. We cannot parse this string and guess that the result is int thus we cannot create an Expression.Multiply between an object and an int. Due to this explicit cast, the only way would be to create the expression from code behind, since there you can do the cast yourself. If you had a "normal" property on the Graphic object that returned an int, you could do it in XAML, i.e. "MyIntProp * 2".

All the best,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Martin
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or