- dcockerham
- Posts: 11
- Joined:
Setting IsFocused without setting IsFocusEngaged
I'm trying to set the focus on a TextBox without engaging the TextBox. The target is a console application, so engaging the TextBox brings up the virtual keyboard, which I don't want to do until the user hits the confirm button. I do want the focus to be on the TextBox when the screen appears, though, so I need to set it to focused somehow. However, I've been struggling with finding a way to focus on the TextBox without engaging it. Whether I use SetFocusAction in the xaml or MoveFocus in the cpp, the TextBox always seems to engage when focused on, with the only exception being when I actually use a Gamepad's directional inputs to manually navigate to the TextBox (which isn't a viable option for setting initial focus). Even if I immediately change the IsFocusEngaged property, like so...
...it seems to be too late to keep the virtual keyboard from coming up. Is there some way to set the Focus to the TextBox without also setting IsFocusEngaged to True?
Code: Select all
<noesis:SetFocusAction />
<ei:ChangePropertyAction PropertyName="IsFocusEngaged" Value="False" />
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: Setting IsFocused without setting IsFocusEngaged
By default controls that get focus are automatically engaged unless they are focused from a gamepad directional input.
To disable that behavior you can call in a control SetUsingFocusEngagement(true) before setting the focus.
I think we can extend our SetFocusAction to include an extra property to indicate if focus engagement should be activated:
Will this be useful for you?
To disable that behavior you can call in a control SetUsingFocusEngagement(true) before setting the focus.
I think we can extend our SetFocusAction to include an extra property to indicate if focus engagement should be activated:
Code: Select all
void SetFocusAction::Invoke(Noesis::BaseComponent*)
{
Noesis::UIElement* element = GetTarget();
if (element != nullptr)
{
Noesis::Control* control = Noesis::DynamicCast<Noesis::Control*>(element);
if (control != nullptr)
{
bool focusEngagement = GetValue<bool>(UsingFocusEngagementProperty);
control->SetUsingFocusEngagement(focusEngagement);
}
element->Focus();
}
}
Code: Select all
<TextBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<noesis:SetFocusAction UsingFocusEngagement="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: Setting IsFocused without setting IsFocusEngaged
Thinking a bit more about this we are going to expose a new Focus() method in the UIElement to indicate if control should be engaged or not when getting the focus, this way the code will be clearer:
Code: Select all
void SetFocusAction::Invoke(Noesis::BaseComponent*)
{
Noesis::UIElement* element = GetTarget();
if (element != nullptr)
{
bool engage = GetValue<bool>(EngageProperty);
element->Focus(engage);
}
}
Code: Select all
<TextBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<noesis:SetFocusAction Engage="False"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
- dcockerham
- Posts: 11
- Joined:
Re: Setting IsFocused without setting IsFocusEngaged
Thanks, this is exactly what I was looking for! I think the proposed extension of SetFocusAction would be quite useful and convenient, though for the time being using SetUsingFocusEngagement(true) is getting the job done well enough.
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: Setting IsFocused without setting IsFocusEngaged
Ok, thanks for the feedback, we already created that extension for the next release.
Who is online
Users browsing this forum: No registered users and 18 guests