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

Column Headers with subscript and superscript in code

3 Answers 840 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 18 Nov 2020, 09:31 PM

Hi

Having grids displaying scientific data - I want to include math symbols with subscript and superscript in the column headers. Xaml markup is sufficient to display the symbols. How do I add the column headers in code. They are read from an extended metadatabase dependent on the users choices, so static xaml styles/templates are not an option. The symbols and column captions may be combined into one header text or divided between two header rows, what ever is convenient.

How can this be done?

 

 

/Brian

3 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 23 Nov 2020, 09:47 AM

Hi Brian,

You can achieve the desired result by adding Run elements to the header TextBlock in code-behind and setting their BaselineAlignment property. Here's an example:

        private object CreateHeader()
        {
            var textBlock = new TextBlock();
            textBlock.Inlines.Add(new Run("2H"));
            textBlock.Inlines.Add(new Run("2")
            {
                FontSize = 10,
                BaselineAlignment = BaselineAlignment.Subscript
            });
            textBlock.Inlines.Add(new Run("O"));

            return textBlock;
        }
This code is the equivalent of defining the following XAML:
                    <telerik:GridViewDataColumn.Header>
                        <TextBlock>
                            2H<Run BaselineAlignment="Subscript" FontSize="10">2</Run>O
                        </TextBlock>
                    </telerik:GridViewDataColumn.Header>
Please give this a try and let me know if such an approach works for you.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Brian
Top achievements
Rank 1
answered on 23 Nov 2020, 11:41 AM

Thanks,

I think what confused me most, was how to read and insert the XAML code from a string read from database. This worked:

DC.Header = (TextBlock)XamlReader.Parse(@"<TextBlock xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" >H<Run BaselineAlignment=""Subscript"">2</Run>O</TextBlock>");

 

/Brian

 

0
Dilyan Traykov
Telerik team
answered on 23 Nov 2020, 03:43 PM

Hi Brian,

Please excuse me, I did not understand that the definition of the header is stored as XAML in the database.

Indeed, in such a scenario the approach you've taken to parse the text seems correct.

Do let me know if I can further assist you with anything else.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

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