locked
Some Functionalities in RichEditBox

    Question

  • Hey Guys...

    I m creating an editor app and so I m using RichEditBox...I need to implement some features in it. I have exhausted everything, but I haven't been able to find solutions for some of my problems.

    1> How do I underline the text in RichEditBox? I know there is a class called Underline and it is used as TextDecorations in TextBlock, but how do I achieve that in RichEditBox?

    2> I wish to select a text and when I tap FontIncrease button, its font size increase, but other texts' size remains same. Similar for FontDecrease button. It works like a charm....However, when I select a text and increase its font, and then when I deselect the text and tap DecreaseFont button, the font size of all texts become equal which shouldn't have happened as earlier selected text's font size was larger. 

    So guys, help me please....

    Saturday, December 27, 2014 11:05 AM

Answers

  • Hi RahulRanjan123,

    First question, will you do these requirements programmatically or via XAML?

    1> How do I underline the text in RichEditBox? I know there is a class called Underline and it is used as TextDecorations in TextBlock, but how do I achieve that in RichEditBox?

    Fro instance I have some text selected in the RichEditBox (txtEditor)  and I want to make them underline.

                ITextSelection selectedText = txtEditor.Document.Selection;
                if (selectedText != null)
                {
                    ITextCharacterFormat charFormatting = selectedText.CharacterFormat;
                    charFormatting.Underline = UnderlineType.Thin;
                    selectedText.CharacterFormat = charFormatting;
                }
    For your second question, I think it could be better to share your code with us for a better analysis.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 29, 2014 3:01 AM
    Moderator

All replies

  • Hi RahulRanjan123,

    First question, will you do these requirements programmatically or via XAML?

    1> How do I underline the text in RichEditBox? I know there is a class called Underline and it is used as TextDecorations in TextBlock, but how do I achieve that in RichEditBox?

    Fro instance I have some text selected in the RichEditBox (txtEditor)  and I want to make them underline.

                ITextSelection selectedText = txtEditor.Document.Selection;
                if (selectedText != null)
                {
                    ITextCharacterFormat charFormatting = selectedText.CharacterFormat;
                    charFormatting.Underline = UnderlineType.Thin;
                    selectedText.CharacterFormat = charFormatting;
                }
    For your second question, I think it could be better to share your code with us for a better analysis.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 29, 2014 3:01 AM
    Moderator
  • I figured second one out on my own....thanks for first one....

    I have another question though... I have inserted an image in RichEditBox through FileOpenPicker....Now I need to resize it too...How do I resize the image ...I mean how do i get an instance of that image and then resize the image...

    Another one :- I have the RichEditBox's Width and Height set as Auto....How do i get its exact value during runtime...since it is set to auto, it will have different values in different screens////

    Monday, December 29, 2014 6:11 PM
  • Hi RagulRanjan123,

    Alright, for the first one. InsertImage method could help you insert correct image with height and width. Looks like there is no possible solution for you to modify the image, but you may need to insert a new image instead of the current one.

    Another possible solution is to save the RichEditBox with rtf format, where we can modify the \pict tag to make a small image.

    Yes, auto will give you different Width and Height, you can try something like ActualHeight and ActualWidth after the control is rendered.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 30, 2014 8:32 AM
    Moderator
  • Hey Jamles Hez I found another problem....

    Once I read files from rtf document and write it to the RichEditBox and then try to align them left,right,center, it does not happen....i.e the default text alignment of document prevails....meaning if originally, the rtf document was aligned to center, then it remains aligned to center itself...if i try to change its allignment, it does not change.... help

    Here is some code samples----- editor is RichEditBox

               

    private async void import_Tapped(object sender, TappedRoutedEventArgs e)
            {
                FileOpenPicker fop = new FileOpenPicker();
                fop.SuggestedStartLocation = PickerLocationId.Desktop;
                fop.FileTypeFilter.Clear();
                fop.FileTypeFilter.Add(".rtf");
                StorageFile fileStream = await fop.PickSingleFileAsync();
                if (null == fileStream)
                {
                    MessageDialog dialog = new MessageDialog("File couldn't be Read.Please try again later!", "Oops! Something went wrong");
                    await dialog.ShowAsync();
                    return;
                }
                IRandomAccessStream stream = await fileStream.OpenAsync(FileAccessMode.Read);
                editor.Document.LoadFromStream(TextSetOptions.FormatRtf, stream);

                stream.Dispose();
            }

    private void align_left_radio_Checked(object sender, RoutedEventArgs e)
            {
                editor.TextAlignment = TextAlignment.Left;
            }

            private void align_center_radio_Checked(object sender, RoutedEventArgs e)
            {
                editor.TextAlignment = TextAlignment.Center;
            }

            private void align_right_radio_Checked(object sender, RoutedEventArgs e)
            {
                editor.TextAlignment = TextAlignment.Right;
            }

    Tuesday, December 30, 2014 1:03 PM
  • This is driving me nuts. Why ain't anybody replying? It has been more than 5 days
    Sunday, January 4, 2015 4:56 PM
  • Please post separate questions in separate threads. Posting multiple questions in the same thread is a good way for them to get missed. I'm marking Jamles' answer to the first question and locking this thread. It looks like you've already reposted the other to its own thread.
    Sunday, January 4, 2015 5:55 PM
    Owner