I want to set focus on conditionally in a WPF
form. Here I have two types of control. One is 'checkbox' and other one is button
. The checkboxes
are getting enabled on some condition, however the button
control(s) are visible by default. I am able to put focus on button
(s) whether checkboxes
are getting enabled or not. Though checkboxes
should get focus over button
when checkboxes
are getting enabled. Kindly, suggest an approach to achieve this please. I have used following code to achieve focus on button
(s)
<Style x:Key="FocusElement" TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=chkCA, Path=IsVisible}" Value="True">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=chkCA}"/>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=btnSaveAll, Path=IsVisible}" Value="True">
<Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=btnSaveAll}"/>
</DataTrigger>
</Style.Triggers>
</Style>
Thanks!