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

Localize aggregate function caption

7 Answers 274 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Licenses
Top achievements
Rank 1
Licenses asked on 14 Jun 2010, 10:04 AM
Hello,

Is there a way to localize the caption of an aggregate function in a RadGridView? I saw that Caption is not a dependency property, so a binding with a resources file like the code sample below will not work.

Are there any plans to change this, or what would be your suggested approach? We use a lot of gridviews in our application, so preferably we don't have to set the caption for each aggregate function in code-behind for every gridview...

<telerikGrid:RadGridView x:Name="list" ItemsSource="{Binding ListItems}"
 
                <telerikGrid:RadGridView.Columns> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Id}"
                        <telerikGrid:GridViewDataColumn.AggregateFunctions> 
                            <telerikData:CountFunction Caption="{Binding Path=ActionResources.GridTotalFooterText, Source={StaticResource ResourceWrapper }}" /> 
                        </telerikGrid:GridViewDataColumn.AggregateFunctions> 
                    </telerikGrid:GridViewDataColumn> 
                    <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Name}"/> 
                </telerikGrid:RadGridView.Columns> 
            </telerikGrid:RadGridView> 


Thanks,
Sodi We

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 15 Jun 2010, 03:44 PM
Hi Sodi We,

There is no problem to localize the caption for the aggregate functions. What you need to do is:
1. Add their values and their translation in your Resource file;
2. Define this Resource file as the default one for your application in App.xaml.cs:

public App()
{
    this.Startup += this.Application_Startup;
    this.Exit += this.Application_Exit;
    this.UnhandledException += this.Application_UnhandledException;
    LocalizationManager.DefaultResourceManager = ES.ResourceManager;
 
    InitializeComponent();
}

In this case the name of the Resource file is "ES"
3. Predefine the TextBlock containing the caption in your xaml file:
<ControlTemplate x:Key="GridViewAggregateResultCellTemplate" TargetType="telerik:GridViewAggregateResultCell">
            <StackPanel Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Orientation="Horizontal" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                <TextBlock Margin="10,0,0,0" TextAlignment="Right" Text="{Binding Caption}" telerik:LocalizationManager.ResourceKey="{Binding Caption}" VerticalAlignment="Center"/>
                <TextBlock Margin="3,0" TextAlignment="Right" Text="{Binding FormattedValue}" VerticalAlignment="Center"/>
            </StackPanel>
        </ControlTemplate>

That's it.
I am sending you a sample project for a reference.


Best wishes,
Maya
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Trude
Top achievements
Rank 2
answered on 09 Jul 2010, 09:06 AM
Why is this not consistent and logical? Here's some XAML from my application:

<telerik:GridViewDataColumn DataMemberBinding="{Binding name}" Width="*">
    <telerik:GridViewDataColumn.Header>
        <TextBlock Text="{Binding LocStr.Str_Name, Source={StaticResource LocStr}}" FontWeight="Bold"/>
    </telerik:GridViewDataColumn.Header>
    <telerik:GridViewDataColumn.AggregateFunctions>
        <telerik:CountFunction Caption="{Binding LocStr.Str_Count, Source={StaticResource LocStr}}"/>
    </telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>

The header column works just fine (I've tested with the footer also), but the caption on the aggregate function throws an exception. It's not consistent - you expect it to work, but no.

Will you consider changing this behaviour?
0
Pavel Pavlov
Telerik team
answered on 09 Jul 2010, 09:23 AM
Hello Jorn,

Aggregate functions are part of the data-engine rather than part of the UI. They are not visual elements, framework elements or dependency objects . This is the reason you can not use binding.

Now the workaround :
Following the good principles of the XAML world , we may use binding in the respective UI element - Aggregate functions are visualized as items in an AggregateResultList . These are part of the UI , may be retemplated and localization and/or bindings should work at that level.

Hope that helps.

Kind regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Trude
Top achievements
Rank 2
answered on 09 Jul 2010, 11:47 AM
Ok, I understand the technicalities behind this, but from a user/developer standpoint maybe it would be a good idea to expose Caption as a dependency property (it may or may not be possible/feasible). Another thought would be to combine ColumnFooter with the results of the aggregate function?
0
Pavel Pavlov
Telerik team
answered on 09 Jul 2010, 01:12 PM
Hi Jorn,

Your requirement is absolutely reasonable and we are already thinking of how to provide more intuitive way to get the captions localized.

What do you mean by " to combine ColumnFooter with the results of the aggregate function" ?

Greetings,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Trude
Top achievements
Rank 2
answered on 09 Jul 2010, 03:27 PM
What I meant was to append the result of the aggregate to the footer text:
<telerik:GridViewDataColumn  DataMemberBinding="{Binding name}" Width="*">
    <telerik:GridViewDataColumn.Footer>
        <TextBlock Text="{Binding LocStr.Str_Count, Source={StaticResource LocStr}}" FontWeight="Bold"/>
    </telerik:GridViewDataColumn.Footer>
    <telerik:GridViewDataColumn.AggregateFunctions>
        <telerik:CountFunction Caption=": "/>
    </telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>

This would result in something like: Count: 51 (if the locale was english). As of now the footer text just overwrites the aggregate. I would prefer to bind directly to the Caption or some other property (maybe a Text property that the caption appends to?).
0
Vlad
Telerik team
answered on 12 Jul 2010, 07:10 AM
Hello Jorn,

 You can use AggregateResultList similar to this demo if you want to bind (and style in desired way) column aggregates. 

Kind regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Licenses
Top achievements
Rank 1
Answers by
Maya
Telerik team
Trude
Top achievements
Rank 2
Pavel Pavlov
Telerik team
Vlad
Telerik team
Share this question
or