int32editbox Focus bug: cursor not visible

Editors for WPF Forum

Posted 14 years ago by Bernhard Wahl
Version: 9.2.0512
Platform: .NET 3.5
Environment: Windows Vista (32-bit)
Avatar
xaml code

<Editors:Int32EditBox x:Name="AmountTextBox"
Focusable="true"
Minimum="0"
Maximum="{Binding Path=MaxAmountValue, Source={StaticResource inventoryWindowViewModel}}"
IsNullAllowed="true"
IsNullContentVisible="False"
PromptIndicatorVisibility="Never"
Grid.Row="4" Grid.Column="1"
Height="{Binding ActualHeight, ElementName=comboBox, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
Style="{StaticResource positioningStyle}"
Value="{Binding Path=Amount, Source={StaticResource inventoryWindowViewModel}, UpdateSourceTrigger=PropertyChanged}">
</Editors:Int32EditBox>

code behind
{
Loaded += OnLoaded;
AmountTextBox.Loaded += OnLoaded;
}

private void OnLoaded(object sender, RoutedEventArgs args)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)
delegate
{
return AmountTextBox.Focus();
}, null);
}

I'm using the int32edit box and it works fine, but i didn't get a visual response if the editbox is focused or not, i can see the cursor, why not? I snooped into the control and check out that the int32editbox has the focus but didn't tunnel the focus to the maskedtextbox ('PART_MaskedTextBox') in the int32editbox.Template!

Please fix this

Comments (5)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bernhard,

The EditBoxes will only forward the focus to the first part if it doesn't already have focus. Your code above will set the focus to the Int32EditBox twice, so the second time it keeps the focus.

If you change your code to verify that Int32EditBox.IsKeyboardFocusWithin is false before calling focus, then it would work fine.


Actipro Software Support

Posted 14 years ago by Bernhard Wahl
Avatar
Thanks for your fast reply.

it didn't work and i think it shouldn't play a role if i want to set the focus one time or thousand-times.

private void OnLoaded(object sender, RoutedEventArgs args)
{
if (!AmountTextBox.IsKeyboardFocusWithin)
{
AmountTextBox.Focus();
}
}

maybe you have another solution for me.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bernhard,

Sorry about the misunderstanding, I misread the code. You can call Focus any number of times. I believe the problem is that the focus is being forwarded to the CheckBox, since that is the first focusable element.

I've added a new overload of the Focus method that will attempt to forward the focus to the first focusable part, then fallback to the default behavior. This will be included in the next maintenance release, but in the meantime you can perform the focus forwarding yourself. The following code should achieve what you want:
private void OnLoaded(object sender, RoutedEventArgs args) {
    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)delegate(object arg) {
        Focus(AmountTextBox);
        return null;
    }, null); 
}

private static bool Focus(PartEditBox editBox) {
    UIElement element = VisualTreeHelperExtended.GetFirstFocusableDescendant(editBox, delegate(DependencyObject obj) {
        if (obj is Part || obj is PartGroup)
            return VisualDescendantFilterBehavior.Continue;
        return VisualDescendantFilterBehavior.ContinueSkipSelf;
    }) as UIElement;

    if (null != element)
        return element.Focus();
    return editBox.Focus();
}


Actipro Software Support

Posted 14 years ago by Bernhard Wahl
Avatar
Tested your solution and check out that the editbox has the focus and i can start writing, but the cursor isn't visible so the user can't see that the editbox is focused! This is a big problem.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Bernhard,

Thanks, I see the issue now. There was an issue with hidden prompt indicators, which I have corrected for the next maintenance release.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.