question

EduardoGomez-1870 avatar image
1 Vote"
EduardoGomez-1870 asked RoyLi-MSFT commented

problem with richedittext

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


windows-uwp
screenshot-248.png (348.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RoyLi-MSFT avatar image
1 Vote"
RoyLi-MSFT answered

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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EduardoGomez-1870 avatar image
0 Votes"
EduardoGomez-1870 answered RoyLi-MSFT commented

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


screenshot-252.png (445.8 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tested your code, it did not work


It does not work

                 case "2":
                     var size = (float)id.SelectedItem;
                     //set size to the Selection
                     richEbitBox.Document.Selection.CharacterFormat.Size = size;
                     break;
                 default:
                     break;
             }
         }
0 Votes 0 ·

Have you set the selected text before you want to change the size?

0 Votes 0 ·

This is the expected behavior, there is only one control can be focused at one time. When you are selecting the ComboBox, it is the only control that is focused. But you could try to manually set the focus state of the RichEditBox after the ComboBox item is selected.

 RichEditBox.Focus(FocusState.Pointer);

Add this line of code at the end of the ComboChanged event. Then the RichEditBox will be focused after you select an item in the ComboBox.

0 Votes 0 ·
EduardoGomez-1870 avatar image
0 Votes"
EduardoGomez-1870 answered RoyLi-MSFT commented

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;

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you have another problem, could you please ask another question in the forum?

0 Votes 0 ·