Whenever I attempt to apply a style selector to dynamically set the DataFormatString, I get a xamlparseexception. I would like to dynamically set the # of decimal places in the cells' data.
My style selector is declared in the usercontrol's resources as:
and is applied in my data column as:
Here is the code for my style selector:
In my styleselector code, the type of the container is GridViewCell. But I can't set a DataFormatString property within a style for a cell, only within the datacolumn. So is it possible to do this with a style selector?
My style selector is declared in the usercontrol's resources as:
<
local:CellDataFormatStyleSelector
x:Key
=
"myDataformatStyleSelector"
/>
<
telerikGridView:GridViewDataColumn
Header
=
"1"
DataMemberBinding
=
"{Binding PeriodQty1}"
TextAlignment
=
"Right"
HeaderTextAlignment
=
"Center"
CellStyleSelector
=
"{StaticResource myDataformatStyleSelector}"
/>
public class CellDataFormatStyleSelector : StyleSelector
{
public override Style SelectStyle(object item, DependencyObject container)
{
var style = new Style(typeof(GridViewDataColumn));
//var row = (GridViewRow)container;
var obj = (ItemLocationperiodDemand)item;
var col = (GridViewCell)container;
if (obj.YearLabel == ApplicationStrings.Composite)
{
style.Setters.Add(new Setter(GridViewDataColumn.DataFormatStringProperty, "{}{0:n1}"));
}
else
{
style.Setters.Add(new Setter(GridViewDataColumn.DataFormatStringProperty, "{}{0:n0}"));
}
return style; }
}