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

Setting Font properties of GridView's cells, etc.

11 Answers 330 Views
GridView
This is a migrated thread and some comments may be shown as answers.
almostEric
Top achievements
Rank 1
Iron
almostEric asked on 16 Jan 2019, 02:38 PM

I have the following implicit style:

    <Style TargetType="telerik:GridViewCell" BasedOn="{StaticResource GridViewCellStyle}">
        <Setter Property="FontFamily" Value="Segoe UI" />
        <Setter Property="FontSize" Value="18" />
        <Setter Property="Foreground" Value="Green" />
    </Style>

However, only the foreground color changes - all font settings are ignored. 

Searched this forum, I don't think it is Theme related, but I am using the Crystal theme

11 Answers, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 18 Jan 2019, 01:56 PM
Hi Eric,

Thank you for the provided code snippet.

I have double check this on my side and the settings are applied to the cell. Attached to this reply you can find the project which I used to test your scenario. May I ask you to test it on your side, and let me know if I need to modify something in order to reproduce this behavior on my side.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
almostEric
Top achievements
Rank 1
Iron
answered on 21 Jan 2019, 03:57 PM

Hi, I downloaded your project and it does indeed work - however it doesn't look like you are using the NOXAML versions of the controls. would that make a difference?

 

Thanks,

Eric

0
Dinko
Telerik team
answered on 22 Jan 2019, 09:47 AM
Hello Eric,

I have double check this on my side and the provided project reference NoXAML binaries. I have merged the required dictionaries in the App.xaml file. In the project, the Crystal theme is applied to the controls. Can you specify how you are merging the NoXAML assemblies in your main application?

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
almostEric
Top achievements
Rank 1
Iron
answered on 22 Jan 2019, 09:52 AM

Sure, in app.xaml:

 

                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/System.Windows.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.Chart.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.Input.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.Navigation.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.ConversationalUI.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.Data.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.DataVisualization.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.GridView.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.FileDialogs.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Crystal;component/Themes/Telerik.Windows.Controls.ScheduleView.xaml" />
                <ResourceDictionary Source="Assets/Styles.xaml" />

0
almostEric
Top achievements
Rank 1
Iron
answered on 23 Jan 2019, 12:27 PM

Hi Dinko,

 

As a test, I copied your keyed style into my window's resources. Same result - the foreground color changed. but the font and fontsize are unaffected

0
Dinko
Telerik team
answered on 24 Jan 2019, 01:36 PM
Hi Eric,

I tried to reproduce this by adding the same assemblies as you did on my side but still the font size and font are applied as expected. I will need to reproduce this behavior so I can further assist you with this. Would it be possible to modify the attached project to mimic your application implementation to reproduce this?

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
almostEric
Top achievements
Rank 1
Iron
answered on 24 Jan 2019, 02:15 PM
will do!
0
almostEric
Top achievements
Rank 1
Iron
answered on 01 Feb 2019, 04:10 PM

Hi Dinko,

I have more information. I realized that in my style.xaml file I also have this:

Style TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontSize" Value="12" />
<Setter Property="TextWrapping" Value="NoWrap"/>
<Setter Property="TextTrimming" Value="None"/>
</Style>

If I change this, it changes the font used in the Grid. If I comment it out, then my implicit/explicit GridViewCell style can set FontFamily and FontSize.

This seems like a bug, since I should be able to have an implicit style for all my text boxes along with being able to individually style a grid cell.

Thanks again for your help

0
Dinko
Telerik team
answered on 05 Feb 2019, 11:23 AM
Hello Eric,

Thank you for the provided code snippet.

This is expected behavior by the framework. Basically, the GridViewCell style is targeting the element directly. The TextBlock inside the GridViewCell inherit these properties (FontFamily, FontSize etc.) from its parent which is GridViewCell. If you create an implicit style for TextBlock, this style will be applied to all TextBlock which does not have explicitly set Style property. This implicit style has a higher priority rather than inheritance. You can read more about this in this MSDN help article. More specifically you can navigate to the Dependency Property Setting Precedence List
section. What you could try is to explicitly set the Style property of every TextBlock to your custom style. 

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
almostEric
Top achievements
Rank 1
Iron
answered on 05 Feb 2019, 01:17 PM

Hi.

I understand all of this.

However, with a TextBlock, while I may have an implicit style, on an individual textbox, I can override that style, either through an explicit style or by setting properties on the control itself. This does not appear to be possible with GridViewCells. Still looks like a bug to me

 

 

0
Dilyan Traykov
Telerik team
answered on 08 Feb 2019, 11:03 AM
Hi Eric,

Another approach I can suggest is to define a separate implicit style in the Resources of the style for the GridViewCell like so:

<Style x:Key="column1" TargetType="telerik:GridViewCell" BasedOn="{StaticResource GridViewCellStyle}">
    <Style.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="FontFamily" Value="Monospace" />
            <Setter Property="FontSize" Value="36" />
            <Setter Property="Foreground" Value="Green" />
        </Style>
    </Style.Resources>
</Style>
 
<Style x:Key="column2" TargetType="telerik:GridViewCell" BasedOn="{StaticResource GridViewCellStyle}">
    <Style.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="FontFamily" Value="Georgia" />
            <Setter Property="FontSize" Value="18" />
            <Setter Property="Foreground" Value="Red" />
        </Style>
    </Style.Resources>
</Style>

This applies the text related properties of the cell as expected at my end whilst preserving the implicit style for the other TextBoxes.

Please try this out at your end as well and let me know if you find such an approach applicable.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
almostEric
Top achievements
Rank 1
Iron
Answers by
Dinko
Telerik team
almostEric
Top achievements
Rank 1
Iron
Dilyan Traykov
Telerik team
Share this question
or