or
<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["PERCEELID"]" />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["PERCEELID"] * 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["PERCEELID"]) * 2); but no success.
If I do the same in code-behind, there is no problem :
Expression<Func<Graphic, double>> 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
<
Grid.Resources
>
<
local:StatusColorConverter
x:Key
=
"ColorConverter"
></
local:StatusColorConverter
>
</
Grid.Resources
>
<
telerik:RadGridView
Name
=
"radGrid1"
HorizontalAlignment
=
"Stretch"
VerticalAlignment
=
"Stretch"
ShowGroupPanel
=
"False"
Margin
=
"5,10,0,100"
DataLoaded
=
"radGrid1_DataLoaded"
SelectionChanged
=
"radGrid1_SelectionChanged"
AutoGenerateColumns
=
"False"
IsFilteringAllowed
=
"False"
ItemsSource
=
"{Binding}"
EnableColumnVirtualization
=
"False"
CanUserResizeColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Name"
DataMemberBinding
=
"{Binding SerialNumber}"
IsReadOnly
=
"True"
UniqueName
=
"Name"
ShowFilterButton
=
"False"
AllowDrop
=
"False"
FooterTextAlignment
=
"Left"
Width
=
"Auto"
/>
<
telerik:GridViewDataColumn
Header
=
"Status"
DataMemberBinding
=
"{Binding StatusDescription}"
IsReadOnly
=
"True"
UniqueName
=
"Status"
ShowFilterButton
=
"False"
Width
=
"Auto"
/>
</
telerik:RadGridView.Columns
>
<
telerik:RadGridView.RowStyle
>
<
Style
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"Background"
Value
=
"{Binding Status,Converter={StaticResource ColorConverter}}"
></
Setter
>
</
Style
>
</
telerik:RadGridView.RowStyle
>
</
telerik:RadGridView
>
public class StatusColorConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Status status = (Status)value;
SolidColorBrush color = null;
switch (status)
{
case Status.Status_A:
case Status.Status_B:
color = new SolidColorBrush(Colors.Red);
break;
case Status.Status_C:
color = new SolidColorBrush(Colors.Green);
break;
default:
// No color by default.
color = new SolidColorBrush();
break;
}
return color;
}