This is a migrated thread and some comments may be shown as answers.
Reduce the available fonts in the RadRichTextBoxRibbonUI
1 Answer 45 Views
This is a migrated thread and some comments may be shown as answers.
papadi
Top achievements
Rank 1
papadi asked on 29 Aug 2012, 10:13 AM
Hi,
I'm using RadRichTextBoxRibbonUI to handle a richtext box. By default the control creates a drop down list with all the available fonts of the system. I would like to restrict my user and provide him/her with specific ones. How do I do that?

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay Demirev
Telerik team
answered on 30 Aug 2012, 02:59 PM
Hello,

The RadRibbonComboBox showing the font families is by default bound to the RegisteredFonts of the FontFamiliesProvider class. The FontFamilyProvider checks what fonts are installed on the machine and adds them to the RegisteredFonts collection. The same collection is also used by the default SelectionMiniToolBar.

In case you would like both the RibbonUI and the SelectionMiniToolBar to use your set of fonts, you can keep the binding and only change the RegisteredFonts like this:

foreach (var font in FontManager.GetRegisteredFonts().ToList())
{
    FontManager.UnregisterFont(font);
}
List<FontFamily> myFonts = new List<FontFamily>() { new FontFamily("Arial"), newFontFamily("Verdana"), new FontFamily("Comic Sans MS") };
foreach (var font in myFonts)
{
    FontManager.RegisterFont(font);
}

This should be done right after the InitializeComponent() method in the constructor of the page. 

If you want to change the fonts only in the RibbonUI, you can do so by removing the binding of the RadRibbonComboBox from the XAML of the page. After that, you can bind the combo box to a set of font families you wish to use or just add them as different ComboBoxItems like this:
<telerik:RadRibbonComboBox CanAutocompleteSelectItems="False" CanKeyboardNavigationSelectItems="False" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=SelectedValue.Tag}" Height="21" IsReadOnly="True" OpenDropDownOnFocus="True" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ChangeFontFamilyCommand}" telerik:ScreenTip.Description="Change the font family." telerik:ScreenTip.Title="Font" Width="132" >
    <telerik:RadRibbonComboBoxItem Content="Arial" Tag="Arial" />
    <telerik:RadRibbonComboBoxItem Content="Comic Sans MS" Tag="Comic Sans MS" />
    <telerik:RadRibbonComboBoxItem Content="Verdana" Tag="Verdana" />
</telerik:RadRibbonComboBox>

I hope this helps.

All the best,
Nikolay Demirev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Asked by
papadi
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Share this question
or