private void CreateNewProfile_Executed(object sender, ExecutedRoutedEventArgs e) { CameraConfigModel.Profiles.Add(new CameraProfile() { Name = $"Copy of '{CameraConfigModel.CurrentCameraProfile.Name}'", CameraPlusConfig = JsonConvert.DeserializeObject <CameraPlusConfig>(JsonConvert.SerializeObject(CameraConfigModel.CurrentCameraProfile.CameraPlusConfig)) }); CameraConfigModel.CurrentCameraProfile = CameraConfigModel.Profiles[CameraConfigModel.Profiles.Count - 1]; ProfileNameTextBox.SelectAll(); ProfileNameTextBox.Focus(); }
private void GetProfileNameDialogWindow_Loaded(object sender, RoutedEventArgs e) { // We need to schedule this to occur later after databinding has completed, otherwise // focus appears in the textbox, but at the start of the suggested name rather than at // the end. Dispatcher.BeginInvoke( (SetFocusCallback) delegate() { ProfileNameTextBox.Select(0, ProfileNameTextBox.Text.Length); ProfileNameTextBox.Focus(); }, System.Windows.Threading.DispatcherPriority.DataBind, null); }
private void GetProfileNameDialogWindow_Loaded(object sender, RoutedEventArgs e) { // We need to schedule this to occur later after databinding has completed, otherwise // focus appears in the textbox, but at the start of the suggested name rather than at // the end. #pragma warning disable VSTHRD001 // Avoid legacy threading switching APIs. // see https://github.com/Microsoft/vs-threading/issues/138 // There is currently no better way to queue an item on // DispatcherPriority.DataBind until the above issue is fixed Dispatcher.BeginInvoke( (SetFocusCallback) delegate() { ProfileNameTextBox.Select(0, ProfileNameTextBox.Text.Length); ProfileNameTextBox.Focus(); }, System.Windows.Threading.DispatcherPriority.DataBind, null); #pragma warning restore VSTHRD001 // Avoid legacy threading switching APIs }
/// <summary> /// Called when window loads. Use it to set focus on the text box correctly. /// </summary> private void GetProfileNameDialogWindow_Loaded(object sender, RoutedEventArgs e) { // We need to schedule this to occur later after databinding has completed, otherwise // focus appears in the textbox, but at the start of the suggested name rather than at // the end. JoinableTaskFactory jtfWithPriority = _threadingService.JoinableTaskFactory .WithPriority(Dispatcher, System.Windows.Threading.DispatcherPriority.DataBind); _ = jtfWithPriority.RunAsync( () => { ProfileNameTextBox.Select(0, ProfileNameTextBox.Text.Length); ProfileNameTextBox.Focus(); return(Task.CompletedTask); }); }
private void PageOneStoryboard_Completed(object sender, EventArgs e) { ProfileNameTextBox.Focus(); }