FocusBehavior Class
In This Article
Focuses a UI control without code-behind.
Namespace: DevExpress.WinUI.Core
Assembly: DevExpress.WinUI.Core.v23.2.dll
NuGet Package: DevExpress.WinUI
#Declaration
#Remarks
#Focus a Control Once it is Loaded
In the following code sample, the FocusBehavior focuses a TextBox control when the control is loaded:
<UserControl ...
xmlns:dx="using:DevExpress.WinUI.Core">
<TextBox Text="This control is focused on startup">
<dx:Interaction.Behaviors>
<dx:FocusBehavior/>
</dx:Interaction.Behaviors>
</TextBox>
</UserControl>
#Focus a Control When an Event is Raised
- Set the EventOwner property to specify an object that raises the event you want to track.
- Specify an object’s event in the EventName property.
The following code sample focuses the TextBox control when a user clicks a Button:
<UserControl ...
xmlns:dx="using:DevExpress.WinUI.Core">
<StackPanel>
<TextBox Text="This control is focused on button click: ">
<dx:Interaction.Behaviors>
<dx:FocusBehavior EventOwner="{x:Bind button}" EventName="Tapped"/>
</dx:Interaction.Behaviors>
</TextBox>
<Button x:Name="button" Content="Click to focus the TextBox"/>
</StackPanel>
</UserControl>
#Focus With a Delay
You can specify a FocusDelay regardless of what triggers the FocusBehavior:
<UserControl ...
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
<StackPanel>
<TextBox Text="This control is focused with a delay">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:FocusBehavior SourceName="btn" EventName="Click" FocusDelay="0:00:01"/>
</dxmvvm:Interaction.Behaviors>
</TextBox>
<Button x:Name="btn" Content="Click to focus the TextBox"/>
</StackPanel>
</UserControl>
#Inheritance
See Also