This project has moved and is read-only. For the latest updates, please go here.

Customising the RichTextBoxFormatBar

Feb 21, 2014 at 5:14 PM
Hi all. Dos anyone have any idea of how to customise the RichTextBoxFormatBar by creating a custom class implementing the IRichTextBoxFormatBar interface?

I don't want to add to the control, just want to take some elements away ie Colour selection, underline.

Thanks
Feb 21, 2014 at 8:51 PM
Hi,

You will have to re-style the RichTextFormatBar by giving it a new ControlTemplate. You can fin the original ControlTemplate in :
-Xceed.Wpf.Toolkit/RichTextFormatBar/Aero2.NormalColor.xaml (windows8)
-Xceed.Wpf.Toolkit/RichTextFormatBar/Generic.xaml (windows7)
under the name : "richTextBoxFormatBarTemplate"
Feb 24, 2014 at 9:34 AM
Great thanks. Where can I find these XAML files?
Feb 24, 2014 at 1:27 PM
Hi,

The SourceCode files are available on CodePLex : https://wpftoolkit.codeplex.com/SourceControl/latest
Feb 24, 2014 at 3:42 PM
Thank you, is it normal procedure to create a new custom Control or does this XAML sit in a resource dictionary?

Sorry, new to WPF.
Feb 25, 2014 at 1:13 PM
Hi,

The current RichTextBoxFormatBar has a default design in a resource Dictionary in the Toolkit. If you want to have a new Design, you have to modify the current control in XAML. Usually, properties lets user modify the behavior of a control, but if special changes needs to be done (like modifying the design), the ControlTemplate of the controls needs to be redone.
Feb 25, 2014 at 2:55 PM
Thanks. I have created a Custom Control, used the xaml source code in Themes/Generic.xaml and created the necessary .cs files from the source code. IsesFormatBar.cs is the control file which inherits from Control.

Here is my Generic.xaml:
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
    xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters;assembly=Xceed.Wpf.Toolkit" 
    xmlns:MyNamespace="clr-namespace:IsesTextEditor">

    <conv:ColorToSolidColorBrushConverter x:Key="ColorToSolidColorBrushConverter" />

    <ControlTemplate TargetType="{x:Type MyNamespace:IsesFormatBar}" x:Key="IsesFormatTemplate">
        <Border Background="Transparent"
              Cursor="Hand"
              ToolTip="Click to Drag">
            <StackPanel VerticalAlignment="Center"
                     Width="75">
                <Line SnapsToDevicePixels="True"
etc etc

                    </StackPanel>

                </StackPanel>
            </Grid>
        </Border>
    </ControlTemplate>

    <!-- =================================================================== -->
    <!-- Style                                                               -->
    <!-- =================================================================== -->
    <Style TargetType="{x:Type MyNamespace:IsesFormatBar}">
        <Setter Property="Template"
              Value="{StaticResource richTextBoxFormatBarTemplate}" />
        <Setter Property="Effect">
            <Setter.Value>
                <DropShadowEffect BlurRadius="5"
                              Opacity=".25" />
            </Setter.Value>
        </Setter>
        <Setter Property="Background"
              Value="Transparent" />
        <Setter Property="IsTabStop"
              Value="false" />
    </Style>
</ResourceDictionary>
I cannot view the tool design in the designer of Generic.xaml, I am getting the message 'Intentionally Left Blank. The document root element is not supported by the visual designer'.

Any ideas?
Feb 25, 2014 at 6:57 PM
Hi,
from what I see, you create a style for objects of type MyNamespace:IsesFormatBar which uses the ControlTemplate "richTextBoxFormatBarTemplate". On the other hand, there is a ControlTemplate (for MyNamespace:IsesFormatBar objects type ), named "IsesFormatTemplate", which is not used.