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

DataFormatString style setter for Money

3 Answers 141 Views
GridView
This is a migrated thread and some comments may be shown as answers.
avinash
Top achievements
Rank 1
avinash asked on 26 Aug 2011, 05:33 AM

hi,

I have many gridviews with Currency Column. I have Created Style setter for DataFormat String. Below is the code

<style x:Key="CurrencyValueStyle" TargetType="telerik:GridViewDataColumn">
 <Setter Property = "DataFormatString" value="{}{0:#,##0.00}"/>
</style>

in GridViewDataColumn im assigning this below code

CellStyle="{StaticResource CurrencyValueStyle}"

But, im getting some XAML parser error.

Where exaclty im doin wrong? please help

Regards,

Avi


3 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 26 Aug 2011, 08:25 AM
Hello Avinash,

 

Since columns in RadGridView are not visual objects you cannot create a style targeted at a Column. If you want to apply a style to GridViewCells within this column you should change the TargetType to GridViewCell:


<Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <Style x:Key="ss" TargetType="telerik:GridViewCell">
                <Setter Property="Background" Value="Red"/>
            </Style>
        </Grid.Resources>
        <telerik:RadGridView x:Name="radGridView" AutoGenerateColumns="False" GroupPanelStyle="{StaticResource GridViewGroupPanelStyle1}" >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn CellStyle="{StaticResource ss}" DataMemberBinding="{Binding LastName}" Header="Last Name"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Married}" Header="Is Married"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>


Regarding the DataFormatString you cannot reference it in a style setter. You may define a DataFormatString as a string Resource and then reference it to a column as shown below:

<UserControl.Resources>   
    <sys:String x:Key="DataFormatString">{0:P}</sys:String>               
</UserControl.Resources>
..
<telerik:GridViewDataColumn DataMemberBinding="{Binding ProductID}"                                                                    DataFormatString="{Binding Source={StaticResource DataFormatString}}"/>
 

All the best,
Vanya Pavlova
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Christopher
Top achievements
Rank 1
answered on 21 May 2012, 12:39 PM
Hello,

I am using the Telerik Silverlight release Q1 2012 and attempting to set the DataFormatString of a GridViewDataColumn to a resource which is set to a date format string.

I have done what you said (see below), but it does not appear to work for me. Am I overlooking something here?

In my resources section (my user control is a RadWindow):

<telerik:RadWindow.Resources>
        <sys:String x:Key="DataFormatString">{}{0:yyyy/MM/dd}</sys:String>
</telerik:RadWindow.Resources>

My RadGridView:

<telerik:RadGridView x:Name="RadDataGrid" Grid.Row="0" SelectionMode="Single" SelectedItem="{Binding SelectedGridItem, Mode=TwoWay}"  ShowGroupPanel="False" AutoGenerateColumns="False" IsReadOnly="True" BorderThickness="0" ItemsSource="{Binding PagedSource, ElementName=DataPager}">
	<telerik:RadGridView.SortDescriptors>
		<telerik:SortDescriptor Member="ClaimDate" SortDirection="Descending"></telerik:SortDescriptor>
	</telerik:RadGridView.SortDescriptors>
	<telerik:RadGridView.Columns>
		<telerik:GridViewDataColumn DataMemberBinding="{Binding ClaimDate}" Header="{Binding Source={StaticResource GridStrings}, Path=ClaimDate}" UniqueName="ClaimDate" 
                                            DataFormatString="{Binding Source={StaticResource DataFormatString}}"/>
	</telerik:RadGridView.Columns>
</telerik:RadGridView>

Thanks,

Christopher
0
Dimitrina
Telerik team
answered on 21 May 2012, 01:17 PM
Hi,

 Please define your resource like so:

<sys:String x:Key="DataFormatString">yyyy</sys:String>

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
avinash
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Christopher
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or