problem with richedittext

Eduardo Gomez 3,416 Reputation points
2019-11-07T08:16:10.87+00:00

private void ComboChanged(object sender, SelectionChangedEventArgs e) {

       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.FontSize = size; // I tried this, and it did not work  

                   

richEbitBox.Document.Selection.CharacterFormat.Size = size; // Also this docent work

                richEbitBox.Document.SetText(TextSetOptions.None, value);  
                break;  
            default:  
                break;  
        }  
    }  

As you can see I am able to change the font, not the sizealt text

Universal Windows Platform (UWP)
0 comments No comments
{count} vote

Accepted answer
  1. Roy Li - MSFT 31,526 Reputation points Microsoft Vendor
    2019-11-07T08:40:37.727+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    You need to set the selected text before you want to change the font or the size. If you haven't selected some text, neither font or size will be changed when you click the ComboBox. So you shouldn't use richEbitBox.Document.GetText() but use richEbitBox.Document.Selection.SetRange() instead.
    For example, the following code shows how to change all the text sizes.

    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;  
                }  
    

    Thanks.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Eduardo Gomez 3,416 Reputation points
    2019-11-07T10:28:14.647+00:00

    OK let me try this, the biggest problem that I have is that when I go and click the combo box, the richEditbox lose its focus alt text

    @RoyLiWicresoftNorthAmericaLtd-0833


  2. Eduardo Gomez 3,416 Reputation points
    2019-11-07T10:32:25.737+00:00

    oh by the way, I have another problem @RoyLiWicresoftNorthAmericaLtd-0833 I want to click a buton and start dictating and click again to stop, right now, I dictate an it will time out

    ` case "0":
    using (SpeechRecognizer recognizer = new SpeechRecognizer()) {
    await recognizer.CompileConstraintsAsync();
    recognizer.Timeouts.InitialSilenceTimeout = TimeSpan.FromHours(1);
    recognizer.Timeouts.EndSilenceTimeout = TimeSpan.FromHours(1);

                        recognizer.UIOptions.AudiblePrompt = "Say whatever you want";  
                        recognizer.UIOptions.ExampleText = "hello world";  
                        recognizer.UIOptions.ShowConfirmation = true;  
    
                        var result = await recognizer.RecognizeWithUIAsync();  
                        var dialog = new MessageDialog(result.Text, "Text");  
    
                        richEbitBox.Document.GetText(TextGetOptions.AdjustCrlf, out string value);  
                        richEbitBox.Document.SetText(TextSetOptions.None, value += result.Text);  
                    }  
                    break;`