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

Get the root object of a DataColumn defined in a RowDetailsTemplate

2 Answers 90 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hans
Top achievements
Rank 1
Veteran
Hans asked on 07 May 2018, 08:50 AM

Hi,

I'm using following method to translate the header of my datagrid columns:

        protected override object ProvideDynamicValue(IServiceProvider serviceProvider)
        {
            //if (UsersModel.LoggedInUser == null)
            //    throw new Exception("User not identified !");

            if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
                return ResourceName;

            var rootObjectProvider = serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;
            var fqName = Global == "False" ? rootObjectProvider?.RootObject.GetType().FullName : "Global";

            return TranslationBL.GetTranslation(!string.IsNullOrWhiteSpace(fqName) ? fqName + "_" + ResourceName : ResourceName);
        }

In XAML:

<telerik:GridViewDataColumn Header="{bx:LocalizeBinding Customer, Global=True}" DataMemberBinding="{Binding CustomerShortName}"/>

Uptill now this was working great.  Now I have a DataGrid defined in a RowDetailsTemplate:

                <telerik:RadGridView.RowDetailsTemplate>
                    <DataTemplate>
                        <TabControl>
                            <TabItem Header="Fini" Background="LightGray">
                                <telerik:RadGridView ItemsSource="{Binding StockFiniDetails}" ShowSearchPanel="False" SelectionMode="Single" AlternationCount="0"                                                                       MaxHeight="350">
                                    <telerik:RadGridView.Resources>
                                        <Style TargetType="telerik:GridViewHeaderCell">
                                            <Setter Property="Background" Value="LightGray"/>
                                        </Style>
                                    </telerik:RadGridView.Resources>
                                    <telerik:RadGridView.Columns>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding Variant, Global=True}" DataMemberBinding="{Binding Variant}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding StockSpec, Global=True}" DataMemberBinding="{Binding StockSpec}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding Passe, Global=True }" DataMemberBinding="{Binding Passe}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding PartNumber, Global=True }" DataMemberBinding="{Binding                                                                                                                  PartNumber}"/>
                                        <telerik:GridViewDataColumn Header="Rayon" DataMemberBinding="{Binding Rayon}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding GrossLength, Global=True }" DataMemberBinding="{Binding                                                                                                                 GrossLength}" DataFormatString="{} {0:N2}" CellStyle="{StaticResource                                                                                                                                             TelerikGridViewCellRightAlignedStyle}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding NetLength, Global=True }" DataMemberBinding="{Binding NetLength}"                                                                                                 DataFormatString="{} {0:N2}" CellStyle="{StaticResource TelerikGridViewCellRightAlignedStyle}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding CostPrice, Global=True }" DataMemberBinding="{Binding CostPrice}"                                                                                                   DataFormatString="{} {0:N2}" CellStyle="{StaticResource TelerikGridViewCellRightAlignedStyle}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding Date, Global=True}" DataMemberBinding="{Binding StockDate}" Style="                                                                                              {StaticResource TelerikGridViewDataColumnShortDateStyle}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding Comment, Global=True}" DataMemberBinding="{Binding Comment}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding Invoice, Global=True}" DataMemberBinding="{Binding InvoiceNumber}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding VIS_ASPECT}" DataMemberBinding="{Binding VisAspect}"/>
                                        <telerik:GridViewDataColumn Header="{bx:LocalizeBinding TEC_ASPECT}" DataMemberBinding="{Binding TecApsect}"/>
                                    </telerik:RadGridView.Columns>
                                </telerik:RadGridView>
                            </TabItem>
                        </TabControl>
                    </DataTemplate>
                </telerik:RadGridView.RowDetailsTemplate>

In this case

    var rootObjectProvider = serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider;

returns null resulting in an invalid translation.

I found out that the ServiceProvider is of type MS.Internal.ServiceProviderContext when the ProvideDynamicValue(IServiceProvider serviceProvider) is called from a 'normal' DataColumn.  When called from a DataColumn defined in a RowDetailsTemplate, the ServiceProvider is of type System.Windows.Markup.ProviceValueServiceProvider.

How can I solve this ?

Best Regards,
Hans

 

2 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 10 May 2018, 08:15 AM
Hello Hans,

Please excuse me for the delay in my reply.

Would it be possible for you to send over a sample project which demonstrates the issue you observe as it is hard for me to suggest a solution based only on the code snippets you provided? If that is the case, please open a new support ticket and attach the project there as our forum system only allows image files to be attached to replies.

If you're unable to isolate this in a separate project, please share some more details on your exact setup so that I can get a better understanding of the issue. More specifically, when is the ProvideDynamicValue method invoked and how is the IServiceProvider parameter passed to this method?

Thank you very much for your cooperation on the matter.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Hans
Top achievements
Rank 1
Veteran
answered on 14 May 2018, 03:16 PM

Hi Dilyan,

Thanks for your reply.  I opened a support ticket and attached  a sample project.  Looking forward to your findings.

Best regards,

Hans

Tags
GridView
Asked by
Hans
Top achievements
Rank 1
Veteran
Answers by
Dilyan Traykov
Telerik team
Hans
Top achievements
Rank 1
Veteran
Share this question
or