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

Multiple font setups for radLabel

3 Answers 285 Views
Themes and Visual Style Builder
This is a migrated thread and some comments may be shown as answers.
Michael Marr
Top achievements
Rank 1
Michael Marr asked on 16 Feb 2010, 08:38 PM
In my application I would like to set font for all labels via themes, which work great.
Most labels sit next to controls which are set to bold.

But as I was adding more labels I noticed that some labels that I have been adding should not be bold, should be using the same font type that the rest of the labels do, but should not be set to bold.

I have tried several things, but any change to font in code is overwritten by the theme.
I have tried looking at setting conditions in the theme, but radlabelelement has nothing useful i can bank on.

Thank you,

3 Answers, 1 is accepted

Sort by
0
Michael Marr
Top achievements
Rank 1
answered on 17 Feb 2010, 12:06 AM
I found the answer for this:

I created a second theme, based on a post I found in these forums. The post said to use, ThemeResolutionService.GetRegisteredControlStyleBuilder which I got working but I must say the documentation on the method lacks. Maybe for many it is obvious what should go in all parameters but it was not for me,

1) the first parameter is the element name you wish to get the style for, my case: typeof(RadLabel).FullName,
2) the second parameter I thought was tricky, as the example provided in the post does not reference how to get it just gives an example of one, I spend a very long time trying out different things, the method i found to get it was,
either user an existing variable or a new in brackets (new RadLabel()).RootElement.Gettype().FullName
This can be applied to any element,
since the full name from my example is "Telerik.WinControls.UI.RadLabel+RadLabelRootElement" seemed easier to use gettype rather than typeof(


Problem with this solution is that I need 2 xml files for label theme rather than just one, and a good naming convention so not to hardcode full names,.

Would be nice if there would be a better solution rather than a 2 xml file one I found.




0
Accepted
Martin Vasilev
Telerik team
answered on 19 Feb 2010, 02:09 PM
Hi Michael Marr,

Thank you for writing. Actually, if you set the font for particular RadLabels at run-time with code, it overrides the application theme settings:

private void Form1_Load(object sender, EventArgs e)
{
    ((TextPrimitive)this.radLabel3.LabelElement.Children[2].Children[1]).Font = new Font("Ariel", 12, FontStyle.Regular);
}

Let me know if you still experience any difficulties with this.

Kind regards,
Martin Vasilev
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
Michael Marr
Top achievements
Rank 1
answered on 19 Feb 2010, 02:49 PM
Thank you for your reply.

For my purposes this is perfect. My goal was just to have some fonts not be bold, while maintaining the use of themes and no hard coded look and feel.
For more complicated solutions in which to have different fonts, (font type, size etc), while maintaining theme settings(all coming from the xml theme files) the 2 theme approach seems to be the only way.
This answer also provided insight on a different question i had, on how to query at run time for the applied theme components.

Thank you
Tags
Themes and Visual Style Builder
Asked by
Michael Marr
Top achievements
Rank 1
Answers by
Michael Marr
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or