none
focus and dictation questions RRS feed

  • Question

  • Hello 

    I have some problems and questions 

    1) I have this code

     private void ComboChanged(object sender, SelectionChangedEventArgs e) {
    
                richEbitBox.Focus(FocusState.Pointer);
    
                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 = id.SelectedItem.ToString();
                        //set size to the Selection
                        richEbitBox.Document.Selection.CharacterFormat.Size = Convert.ToInt32(size);
                        break;
                    default:
                        break;
                }
            }
    
            private void Container_Loaded(object sender, RoutedEventArgs e) {
                fontBox.Text = richEbitBox.Document.GetDefaultCharacterFormat().Name;
                fontSizeBox.Text = richEbitBox.Document.GetDefaultCharacterFormat().Size.ToString();
            }
    
            private void richEbitBox_LostFocus(object sender, RoutedEventArgs e) {
    
                richEbitBox.Focus(FocusState.Programmatic);
            }
        }
    }
    
    

     What I want to do is never lose focus of it, I tried to implement the method manualy or calling the richEditBox.Focus on the event handler of the combo boxes but it does not work. Take Micosoft word for example when I select a character and go change , the mouse is still visible. This picture show the text area lose focus, when I change things (Font name, Size, Bold, Italic, Underline)

    2) I want to enable continues dictation, I manege to implement this, but it timeout 

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

    I follow the documentation of Microsoft for continuous dictation, but is hard to follow.

    3) I am trying to access Microsoft QA (Preview) but I cant, it always tell me that the page doesn't exist

    4) I am trying to stick with mvvm as much as possible, but I dont know how to pass my buttons tags through a CommandParametter and change my richeditbox base on my tag, I also keep track of my characters and textblock do not have commandParametter. My questions is,=. is really that bad to have code, in code behind?

    Thank you so much for your valuable time, and I am sorry to waste it, I am a Microsoft fan and learning the UWP apis


    Saturday, November 9, 2019 8:08 AM

Answers

  • Hi,

    >>What I want to do is never lose focus of it, I tried to implement the method manualy or calling the richEditBox.Focus on the event handler of the combo boxes but it does not work. Take Micosoft word for example when I select a character and go change , the mouse is still visible. This picture show the text area lose focus, when I change things (Font name, Size, Bold, Italic, Underline)

    No, it is not possible for UWP apps. It is not possible to keep the RichEditBox always focused when you need to manipulate other controls. This is by design. 

    >>I want to enable continues dictation, I manege to implement this, but it timeout

    Could you please give more details about this? Is it a exception or just a error state? Could you please tell me more about how you get this? The continuous dictation of speech recognization has a time limitation, if you don't speak a word and it will just stop.

    >>I am trying to access Microsoft QA (Preview) but I cant, it always tell me that the page doesn't exist

    Could you please try to clean the cache of your browser and access it again? Please refer to this thread:Clear your Chrome cache if you can not access Microsoft Q&A (Preview) using Chrome

    >> I dont know how to pass my buttons tags through a CommandParametter and change my richeditbox base on my tag

    I assume you had implemented the ICommand interface to bind the Button click event to a command. If you want to pass the tag as CommandParameter, you could try to bind the button self as the parameter. 

    Like this:

     <Button x:Name="MyButton" Content="Do Something" Tag="1" Command="{Binding Path=ActionCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" />

    Then in the command handler where you implement the ICommand interface, pass button's tag as a string parameter to the Action :

         private Action<string> _action;
    
            public CommandHandler(Action<string> action)
            {
                this._action = action;
            }
    
            public void Execute(object parameter)
            {
                Button button = (Button)parameter;
                string str = button.Tag.ToString();
                this._action(str);
            }
    After that, in the ViewModel, add the following code:
      public ICommand ActionCommand
            {
                get
                {
                    return new CommandHandler(str => this.GreetMeAction(str));
                }
            }
    
            private void GreetMeAction(string str)
            {
                //get the button tag as string show it in a textblock.
                HelloText = str;
    
            }

    >>My questions is,=. is really that bad to have code, in code behind?

    It's hard to say. Everyone has a different opinion about this. My opinion it that, if you could do one thing in MVVM, it's better to do it in the MVVM. It's not bad to have code in code behind, but just don't put everything in the code behind.

    The last thing is, please ask one question in one thread next time.

    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.


    Monday, November 11, 2019 7:15 AM
    Moderator

All replies

  • Hi,

    >>What I want to do is never lose focus of it, I tried to implement the method manualy or calling the richEditBox.Focus on the event handler of the combo boxes but it does not work. Take Micosoft word for example when I select a character and go change , the mouse is still visible. This picture show the text area lose focus, when I change things (Font name, Size, Bold, Italic, Underline)

    No, it is not possible for UWP apps. It is not possible to keep the RichEditBox always focused when you need to manipulate other controls. This is by design. 

    >>I want to enable continues dictation, I manege to implement this, but it timeout

    Could you please give more details about this? Is it a exception or just a error state? Could you please tell me more about how you get this? The continuous dictation of speech recognization has a time limitation, if you don't speak a word and it will just stop.

    >>I am trying to access Microsoft QA (Preview) but I cant, it always tell me that the page doesn't exist

    Could you please try to clean the cache of your browser and access it again? Please refer to this thread:Clear your Chrome cache if you can not access Microsoft Q&A (Preview) using Chrome

    >> I dont know how to pass my buttons tags through a CommandParametter and change my richeditbox base on my tag

    I assume you had implemented the ICommand interface to bind the Button click event to a command. If you want to pass the tag as CommandParameter, you could try to bind the button self as the parameter. 

    Like this:

     <Button x:Name="MyButton" Content="Do Something" Tag="1" Command="{Binding Path=ActionCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" />

    Then in the command handler where you implement the ICommand interface, pass button's tag as a string parameter to the Action :

         private Action<string> _action;
    
            public CommandHandler(Action<string> action)
            {
                this._action = action;
            }
    
            public void Execute(object parameter)
            {
                Button button = (Button)parameter;
                string str = button.Tag.ToString();
                this._action(str);
            }
    After that, in the ViewModel, add the following code:
      public ICommand ActionCommand
            {
                get
                {
                    return new CommandHandler(str => this.GreetMeAction(str));
                }
            }
    
            private void GreetMeAction(string str)
            {
                //get the button tag as string show it in a textblock.
                HelloText = str;
    
            }

    >>My questions is,=. is really that bad to have code, in code behind?

    It's hard to say. Everyone has a different opinion about this. My opinion it that, if you could do one thing in MVVM, it's better to do it in the MVVM. It's not bad to have code in code behind, but just don't put everything in the code behind.

    The last thing is, please ask one question in one thread next time.

    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.


    Monday, November 11, 2019 7:15 AM
    Moderator
  • Thanks you so much @Roy

    by the way I still cant access QA

    Monday, November 11, 2019 3:16 PM
  • Hi,

    Are you using chrome now? If it is, have you tried to use Edge?

    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.

    Tuesday, November 12, 2019 6:59 AM
    Moderator
  • I am using the new Edge, powered by chomium, I also tried chrome
    Tuesday, November 12, 2019 1:12 PM
  • @EG87. You should be able to access Q&A now. We fixed the issue. Thanks a lot for reporting and sorry for the inconvenience.
    Tuesday, November 12, 2019 10:59 PM
    Administrator