Int32 Editor Focus not working :-(

Editors for WPF Forum

Posted 15 years ago by Brette Esterbrooks
Version: 9.2.0511
Platform: .NET 3.5
Environment: Windows Vista (32-bit)
Avatar
I have a Int32 text box on a screen. If I set focus to the control when the screen is first loaded the cursor does not appear in the control. We know by looking at snoop that the control does actually have focus however the first "part" within the control does not. This makes me sad.

<Window x:Class="WpfApplication3.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Editors="clr-namespace:ActiproSoftware.Windows.Controls.Editors;assembly=ActiproSoftware.Editors.Wpf30"
        Loaded="Window1_OnLoaded"
        Title="Window1"
        Height="300"
        Width="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Label Grid.Column="0">Case Number</Label>
        <Editors:Int32EditBox Grid.Row="0"
                              Grid.Column="1"
                              Name="txtCaseNumber"
                              Width="100"
                              HorizontalAlignment="Left"
                              VerticalAlignment="Top" />
    </Grid>
</Window>


using System.Windows;

namespace WpfApplication3
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Window1_OnLoaded(object sender, RoutedEventArgs e)
        {
            txtCaseNumber.Focus();
        }
    }
}

Comments (2)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Brette,

By default, the Int32EditBox (as well as the other edit boxes) will pass the focus on to the first focusable child when it receives focus.

As you have stated, the Int32EditBox does in fact get the focus on startup. The problem is that when it receives it during the load, it doesn't have an visual children to pass the focus to.

What you can do is delay the setting of the focus, so that the control does have it's visual children generated. If you use this code in your Loaded handler, then it shoudl work as expected:
private void Window1_Loaded(object sender, RoutedEventArgs e) {   
    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)delegate(object arg) {   
        txtCaseNumber.Focus();   
        return null;   
    }, null);   
}


Actipro Software Support

Posted 15 years ago by Brette Esterbrooks
Avatar
That makes sense. We will take a crack at that. Thanks again for the prompt reply.
The latest build of this product (v24.1.3) was released 27 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.