Rich text custom column

7 posts, 0 answers
  1. Rotem
    Rotem avatar
    25 posts
    Member since:
    Sep 2010

    Posted 24 Aug 2011 Link to this post

    Hi, I’m using custom column that contains telerik rich text box.
    My problem is that when I mark some text in the rich text box and clicking on one of the formatting options in the formatting popup dialog the focus of the richtext box is lost and the formatting is not applied on the selected text.

    Here is my code

    public class RichTextColumn : Telerik.Windows.Controls.GridViewBoundColumnBase  //GridViewColumn

    {

      public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)

      {

         var richTextBox = cell.Content as RadRichTextBox;

     

         if (richTextBox == null)

         {

              richTextBox = new RadRichTextBox();

              richTextBox.IsReadOnly = true;

              richTextBox.SetBinding(RadRichTextBehaviours.RTFDocumentProperty, DataMemberBinding);

              richTextBox.IsHitTestVisible = false;

              richTextBox.AcceptsTab = false;

              richTextBox.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

              richTextBox.IsSpellCheckingEnabled = false;

              richTextBox.VerticalAlignment = VerticalAlignment.Top;

              richTextBox.BorderThickness = new Thickness(0);

              RadRichTextBehaviours.SetCancelSelectionOnLostFocus(richTextBox, true);

     

              cell.Content = richTextBox;

         }

         else

         {

              richTextBox.IsReadOnly = true;

         }

     

         return richTextBox;

      }

     

      public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)

      {

         var richTextBox = new RadRichTextBox();

         richTextBox.SetBinding(RadRichTextBehaviours.RTFDocumentProperty, DataMemberBinding);

     

         richTextBox.AcceptsTab = false;

         richTextBox.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

         richTextBox.IsSpellCheckingEnabled = false;

         richTextBox.VerticalAlignment = VerticalAlignment.Top;

         richTextBox.BorderThickness = new Thickness(0);

         RadRichTextBehaviours.SetCancelSelectionOnLostFocus(richTextBox, true);

     

         return richTextBox;

      }

    }

     

    Can you please help?
    Thanks, Rotem.

  2. Boby
    Admin
    Boby avatar
    595 posts

    Posted 30 Aug 2011 Link to this post

    Hi Rotem,
    I am not sure if i understand your problem correctly, but some of the commands on the SelectionMiniToolBar works with the selection in RadRichTextBox, so maybe the problem lies within the SetCancelSelectionOnLostFocus attached property. Could you please try to remove it and check if the mini toolbar works as expected.
    If this doesn't help please you could send us a sample project (attached to a support ticket) illustrating the problem, so that we can further investigate it.

    Greetings,
    Boby
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Rotem
    Rotem avatar
    25 posts
    Member since:
    Sep 2010

    Posted 30 Aug 2011 Link to this post

    Hi boby,

    The LostFocus attached property don’t cause the problem, I have removed it and still I can’t use the SelectionMiniToolBar to change the richbox text style.

    I saw that when I click on the Mini Tool Bar, the edited cell is losing its focus and then the grid is getting out from edit mode, and the cell content replaced to another rich text box. Because the SelectionMiniToolBar was called by richtext from the edit template that is not exist in the moment, the text is not being updated with the new style.

    So I need to rephrase my question:

    How can I check if I lost the focus to the SelectionMiniToolBar, and in this case to keep the grid on edit mode?

  5. Boby
    Admin
    Boby avatar
    595 posts

    Posted 02 Sep 2011 Link to this post

    Hello Rotem,
    You can use the following workaround:
    this.radGridView.CellValidating += (s, e) =>
        {
            // this depends on your cell edit template
            RadRichTextBox radRichTextbox = (RadRichTextBox)e.EditingElement;
             
            SelectionMiniToolBar selectionMiniToolBar = ((SelectionMiniToolBar)radRichTextbox.SelectionMiniToolBar);
     
            e.IsValid = !selectionMiniToolBar.IsKeyboardFocusWithin;
        };

    Don't hesitate to contact us if you have other questions.


    Greetings,
    Boby
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  6. Rotem
    Rotem avatar
    25 posts
    Member since:
    Sep 2010

    Posted 02 Sep 2011 Link to this post

    Hi boby

    Your solution solves the problem, thanks.
     But at loss of focus cancelation, the cell is marked with a red frame.
     How do I hide that red frame?
  7. Rotem
    Rotem avatar
    25 posts
    Member since:
    Sep 2010

    Posted 04 Sep 2011 Link to this post

     

    I’ve changed the GridViewEditorPresenter and removed the ValidationErrorElement.
    It’s working on a sample solution, but on my project the Validation Error is still visible.
    I saw on snoop that now the red border is coming from Background_Invalid element in the GridViewCell Template.

     

    This is the code that worked on the sample program:

     

     

    <Style TargetType="{x:Type telerik:GridViewEditorPresenter}">

        <Setter Property="Template">

            <Setter.Value>

    <ControlTemplate TargetType="{x:Type telerik:GridViewEditorPresenter}">

        <Grid>

            <ContentPresenter Margin="1,1,1,2" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

            <!--<Border x:Name="ValidationErrorElement" Margin="1,1,1,2" Visibility="Collapsed" BorderBrush="#FF00000C" BorderThickness="1" CornerRadius="1">

    <Popup StaysOpen="True" IsOpen="{TemplateBinding IsVisible}" Placement="Right">

        <TextBlock Background="Red" Foreground="White" Text="{TemplateBinding ErrorMessage}" />

    </Popup>

            </Border>-->

        </Grid>

        <!--<ControlTemplate.Triggers>

            <Trigger Property="IsContentValid" Value="False">

    <Setter Property="Visibility" TargetName="ValidationErrorElement" Value="Visible" />

            </Trigger>

        </ControlTemplate.Triggers>-->

    </ControlTemplate>

            </Setter.Value>

        </Setter>

        <Setter Property="VerticalAlignment" Value="Stretch" />

        <Setter Property="HorizontalAlignment" Value="Stretch" />

        <Setter Property="VerticalContentAlignment" Value="Center" />

        <Setter Property="HorizontalContentAlignment" Value="Stretch" />

        <Setter Property="Padding" Value="1,1,1,2" />

    </Style>

     

     

    How can I hide the Background_Invalid from the GridViewCell without replacing its entire template?

     

  8. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 06 Sep 2011 Link to this post

    Hi Rotem,

     

    The ValidationErrorElement within the GridViewEditorPresenter is responsible for validating a cell when it is in edit mode. The same element resides within the template of GridViewCell as a tooltip of Background_Invalid. The recommended approach is to predefine the template of GridViewCell remove the defined ToolTip and leave empty its Invalid trigger. 



    All the best,
    Vanya Pavlova
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top
UI for WPF is Visual Studio 2017 Ready