Answer by BrightShadow for WPF and initial focus
Above solution was not working as expected for me, I've changed slightly the behavior proposed by Mizipzor as following:From this partif ((bool)args.NewValue) { control.Loaded += (sender, e) =>...
View ArticleAnswer by G.Dealmeida for WPF and initial focus
If you are like me, and you are using some frameworks that, somehow, mess up with the basic focus behaviors, and make all solutions above irrelevant, you can still do this :1 - Note the element which...
View ArticleAnswer by Drew Noakes for WPF and initial focus
A minimal version of Mizipzor's answer for C# 6+.public static class FocusBehavior{ public static readonly DependencyProperty GiveInitialFocusProperty =...
View ArticleAnswer by BSG for WPF and initial focus
I also faced the same problem. I had three text boxes inside canvas container and wanted the first text box to be focused when the user control opens. WPF code followed MVVM pattern. I created a...
View ArticleAnswer by Simon Gillbee for WPF and initial focus
You can easily have the control set itself as the focused element in XAML.<Window><DataGrid FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}">...
View ArticleAnswer by Vladik Y for WPF and initial focus
Had same problem solved it with simple solution:In the main window:<Window .... FocusManager.FocusedElement="{Binding ElementName=usercontrolelementname}" ... />In the user control:private void...
View ArticleAnswer by dnk.nitro for WPF and initial focus
<Window FocusManager.FocusedElement="{Binding ElementName=yourControlName}">
View ArticleAnswer by Mizipzor for WPF and initial focus
Based on the accepted answer implemented as an attached behavior:using System.Windows;using System.Windows.Controls;using System.Windows.Input;namespace UI.Behaviors{ public static class FocusBehavior...
View ArticleAnswer by OrPaz for WPF and initial focus
After having a 'WPF Initial Focus Nightmare' and based on some answers on stack, the following proved for me to be the best solution. First, add your App.xaml OnStartup() the...
View ArticleAnswer by Sean for WPF and initial focus
This works, too:<Window FocusManager.FocusedElement="{Binding ElementName=SomeElement}"><DataGrid x:Name="SomeElement"> ...</DataGrid></Window>
View ArticleAnswer by Joe White for WPF and initial focus
I found another possible solution. Mark Smith posted a FirstFocusedElement markup extension for use with FocusManager.FocusedElement.<UserControl x:Class="FocusTest.Page2"...
View ArticleAnswer by Joe White for WPF and initial focus
I had the bright idea to dig through Reflector to see where the Focusable property is used, and found my way to this solution. I just need to add the following code to my Window's constructor:Loaded +=...
View ArticleWPF and initial focus
It seems that when a WPF application starts, nothing has focus.This is really weird. Every other framework I've used does just what you'd expect: puts initial focus on the first control in the tab...
View Article