FocusBehavior Class
Allows you to set the focus to a UI control without utilizing code-behind.
Namespace: DevExpress.Mvvm.UI
Assembly:
DevExpress.Xpf.Core.v20.1.dll
NuGet Packages:
DevExpress.WindowsDesktop.Wpf.Core, DevExpress.Wpf.Core
Declaration
[TargetType(typeof(Control))]
public class FocusBehavior :
EventTriggerBase<Control>
<TargetType(GetType(Control))>
Public Class FocusBehavior
Inherits EventTriggerBase(Of Control)
See FocusBehavior to learn more.
Example
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
namespace Example.ViewModel {
[POCOViewModel]
public class MainViewModel {
}
}
<UserControl x:Class="Example.View.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ViewModel="clr-namespace:Example.ViewModel"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignHeight="500" d:DesignWidth="600"
DataContext="{dxmvvm:ViewModelSource Type=ViewModel:MainViewModel}">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="10">
<TextBlock Text="This control is focused on button click: " VerticalAlignment="Center"/>
<TextBox Text="Click the bottom button">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:FocusBehavior SourceName="bt" EventName="Click"/>
</dxmvvm:Interaction.Behaviors>
</TextBox>
<Button x:Name="bt" Content="Click to focus the TextBox"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="10">
<TextBlock Text="This control is focused on startup: " VerticalAlignment="Center"/>
<TextBox Text="Focus is here">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:FocusBehavior/>
</dxmvvm:Interaction.Behaviors>
</TextBox>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Namespace Example.ViewModel
<POCOViewModel> _
Public Class MainViewModel
End Class
End Namespace
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FocusBehavior class.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
See Also