I have Grid with multiple Textboxes. Depending on actions the user might take focus should be changed to one of the textboxes. My current solution uses a string property in the ViewModel and a data trigger in xaml to change focus. It works nicely but it seems a rather roundabout way to achieve this so I was wondering if it could be done in a clearner way?
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding FocusedItem}" Value="number">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=number}"/>
</DataTrigger>
<DataTrigger Binding="{Binding FocusedItem}" Value="name">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=name}"/>
</DataTrigger>
<DataTrigger Binding="{Binding FocusedItem}" Value="id">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=id}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
As you can see the value of the property and the name of the element is the same so I would like to do this i a single trigger instead of having one trigger per element.
Maybe someone can come up with a cleaner way?
Thanks in advance