The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
Using RichEdiBox RRS feed

  • Question

  • Hello 

    This is my first time publishing here. 

    This is what i am doing, I cannot complete this

    • I have 2 ComboBoxes (one for the font size, and another one for the font name)
    • I have a RichEditBox, where you can write, bold, italic, etc
    • I have an event for the ConboBox selection change
    • I can change the font name without any problem, but the font size, doesn't want to be set

    private void ComboChanged(object sender, SelectionChangedEventArgs e) { var id = sender as ComboBox; switch (id.Tag) { case "1": //Todo implement new font name string fontName = id.SelectedItem.ToString(); richEbitBox.Document.Selection.CharacterFormat.Name = fontName; break; case "2": var size = (float)id.SelectedItem; break; default: break; } }

    Tuesday, November 5, 2019 10:20 PM

Answers

  •     richEbitBox.Document.GetText(TextGetOptions.AdjustCrlf, out string value);
                var id = sender as ComboBox;
    
                switch (id.Tag) {
    
                    case "1":
                        //Todo implement new font
                        string fontName = id.SelectedItem.ToString();
                        richEbitBox.Document.Selection.CharacterFormat.Name = fontName;
                        break;
                    case "2":
                        var size = (float)id.SelectedItem;
                        richEbitBox.Document.Selection.CharacterFormat.Size = size // does not work
                        break;
                    default:
                        break;
                }
            }

    • Marked as answer by EG87 Saturday, November 9, 2019 8:01 AM
    Thursday, November 7, 2019 8:28 AM
  • Hi,

    I've replied you in Microsoft Q&A forum. You could check that.

    Best regards,

    Roy


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.


    Thursday, November 7, 2019 8:41 AM
    Moderator

All replies

  • Hi,

    So you want to change the text size when the ComboBox's selected item is changed, right?

    You could directly change the Size property of the CharacterFormat like what you did for font Name.

    Like this:

     switch (id.Tag)
                {
    
                    case "1":
                        //Todo implement new font name
                        string fontName = id.SelectedItem.ToString();
                        MyBox.Document.Selection.CharacterFormat.Name = fontName;
                        break;
                    case "2":
                        var size = (float)id.SelectedItem;
                        //set size to the Selection
                        MyBox.Document.Selection.CharacterFormat.Size = size;
                        break;
                    default:
                        break;
                }


    Best regards,

    Roy


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Wednesday, November 6, 2019 3:19 AM
    Moderator
  • Thank you sir, but for some reason it doesn't work, I think the main problem is that evrery time I click on the combo boxes, the EditText gets out of focus. If this were the real issue, why can I change the font?  
    Wednesday, November 6, 2019 10:28 PM
  • Hi,

    You need to set the selected text before you want to change the font or the size. In the beginning, I thought you've already known this and set the selected text somewhere else. If you haven't selected some text, neither font or size will be changed when you click the ComboBox. 

    To select the text in the RichEditBox, you could use ITextRange.SetRange(Int32, Int32) Method.

    Like this:

                MyBox.Document.Selection.SetRange(0, MyBox.Document.Selection.EndPosition);
                switch (id.Tag)
                {
    
                    case "1":
                        //Todo implement new font name
                        string fontName = id.SelectedItem.ToString();
                        MyBox.Document.Selection.CharacterFormat.Name = fontName;
                        break;
                    case "2":
                        var size = (float)id.SelectedItem;
                        //set size to the Selection
                        MyBox.Document.Selection.CharacterFormat.Size = size;
                        break;
                    default:
                        break;
                }

    Best regards,

    Roy


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    Thursday, November 7, 2019 4:42 AM
    Moderator
  •     richEbitBox.Document.GetText(TextGetOptions.AdjustCrlf, out string value);
                var id = sender as ComboBox;
    
                switch (id.Tag) {
    
                    case "1":
                        //Todo implement new font
                        string fontName = id.SelectedItem.ToString();
                        richEbitBox.Document.Selection.CharacterFormat.Name = fontName;
                        break;
                    case "2":
                        var size = (float)id.SelectedItem;
                        richEbitBox.Document.Selection.CharacterFormat.Size = size // does not work
                        break;
                    default:
                        break;
                }
            }

    • Marked as answer by EG87 Saturday, November 9, 2019 8:01 AM
    Thursday, November 7, 2019 8:28 AM
  • Hi,

    I've replied you in Microsoft Q&A forum. You could check that.

    Best regards,

    Roy


    "Developing Universal Windows apps" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.


    Thursday, November 7, 2019 8:41 AM
    Moderator
  • I cant post anymore, or access Microsoft QA HELP
    • Edited by EG87 Saturday, November 9, 2019 8:03 AM
    Saturday, November 9, 2019 8:02 AM