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

RadRichTextBox "invisible" caret

2 Answers 301 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 30 Nov 2018, 11:21 AM

Hello,

Could you, please, help me to make RadRichTextBox's caret visible?

I've tried to use solution with custom CaretFactory from this post... No results, unfortunately

Is it possible to make caret visible?

 

Here is some code examples of RadRichTextBox usage (my telerik version: 2018.3.911.45):

<telerik:RadRichTextBox x:Name="descriptionRichBox" 
            Grid.Row="0" Grid.Column="1" Margin="0,2,0,5"  MinHeight="70"      
 BorderThickness="{Binding IsReadOnly, Converter={localConverters:BoolToBorderThicknessConverter}}"
            FontSize="{Binding Source={StaticResource MediumNormal}, Path=Size}"
            FontFamily="{Binding Source={StaticResource MediumNormal}, Path=Family}"
            IsReadOnly="{Binding IsReadOnly}" GotFocus="RichTextBox_GotFocus"
            DocumentInheritsDefaultStyleSettings="True" IsSpellCheckingEnabled="False"
                                />
<telerik:HtmlDataProvider RichTextBox="{Binding ElementName=descriptionRichBox}"
    Html="{Binding EditableObject.Description, Mode=TwoWay}"       
                                  />
<Style TargetType="telerik:Caret">
  <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="telerik:Caret" >
                <Grid x:Name="RootElement"  >
                    <ScrollViewer   x:Name="ContentElement" BorderThickness="0" Padding="0" />
                            <Rectangle x:Name="Rectangle" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="VerticalAlignment" Value="Top" />
    <Setter Property="AcceptsReturn" Value="True" />
    <Setter  Property="CaretBrush" Value="Black"/>
    <Setter Property="Padding" Value="0" />
    <Setter Property="Foreground" Value="Transparent" />
</Style>
public class DescriptionCaretFactory : ICaretFactory
    {
        public Caret CreateCaret()
        {
            return new Caret { Width = 2, MinWidth = 2, Height=5,
                IsBlinking = true, IsEnabled = true,
                Visibility = System.Windows.Visibility.Visible,
                ToolTip = "test caret",
                CaretBrush = System.Windows.Media.Brushes.Black, };
        }
    }

 

Best regards,

Ivan.

2 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 05 Dec 2018, 11:58 AM
Hello Ivan,

There is an internal logic adding properties for the caret that should be executed in order for the caret to be visible. That is why you will need to set a specific Name of the ScrollViewer when defining the template for the caret:
<ControlTemplate TargetType="telerik:Caret" >
    <Grid x:Name="RootElement">
        <ScrollViewer BorderThickness="0" Padding="0" >
            <ScrollViewer.Name>PART_ContentHost</ScrollViewer.Name>
        </ScrollViewer>
 
        <Rectangle x:Name="Rectangle" Width="30" Height="20" UseLayoutRounding="True"/>
    </Grid>
</ControlTemplate>

As to the creation of a custom caret, it seems like it is invisible due to the small size values. If you increase them (especially the height), you should be able to see the caret in the UI.

Would you share why you need these customizations? What are you trying to achieve? I would like to mention that the RadRichTextBox class exposes the CaretColor property in case you need to only change the color.

Hope this is helpful.

Regards,
Tanya
Progress Telerik
Get quickly 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
Ivan
Top achievements
Rank 1
answered on 07 Dec 2018, 10:32 AM

I found, that default RadRichTextBox and Caret styles are missing. After applying them, carret is visible and works fine.

Thank you for your answer.

 

Regards,

Ivan

Tags
RichTextBox
Asked by
Ivan
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Ivan
Top achievements
Rank 1
Share this question
or