Setting focus to input box in an InputDialog using MahApps

455 views Asked by At

We've made our own search dialog based on the InputDialog from MahApps Dialog examples, and it does work, but there are two issues with it:

  1. When opened it does not automatically focus in the search field, so you have to click it before starting to type your search
  2. If possible, we would like to autoselect the first entry in the list, so that you don't need to first select the entry in the list, and then hit the OK button

Can you help with either of these? The first is the most important, as the users start typing quite often before noticing that the focus is not in the search field.

1

There are 1 answers

0
holroy On BEST ANSWER

When working with providing some code excerpts to get help, which was basically a copy-and-paste from the example link I provided in the question, I discovered there was a dependency between the class name and the title of the dialog.

<dialogs:BaseMetroDialog x:Class="Some.Path.Dialogs.SearchDialog"
  ...
  d:DesignHeight="500" d:DesignWidth="800" 
  Title="SearchDialog" Background="White">
  ...
</dialogs:BaseMetroDialog>

When the Title matched the last part of Class the focus was set properly. Regarding the auto-select, that turns out not be related to the Metro.MahApps interface, but only internal code, and I found an entry point which sounds promising to get my achieved goal.