Localize aggregate function caption

8 posts, 0 answers
  1. Sodi We
    Sodi We avatar
    160 posts
    Member since:
    Apr 2010

    Posted 14 Jun 2010 Link to this post

    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
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 15 Jun 2010 Link to this post

    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.
  3. DevCraft banner
  4. Jorn
    Jorn avatar
    222 posts
    Member since:
    Jun 2009

    Posted 09 Jul 2010 Link to this post

    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?
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 09 Jul 2010 Link to this post

    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
  6. Jorn
    Jorn avatar
    222 posts
    Member since:
    Jun 2009

    Posted 09 Jul 2010 Link to this post

    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?
  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 09 Jul 2010 Link to this post

    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
  8. Jorn
    Jorn avatar
    222 posts
    Member since:
    Jun 2009

    Posted 09 Jul 2010 Link to this post

    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?).
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 12 Jul 2010 Link to this post

    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
Back to Top
DevCraft banner