0

I want to set focus on conditionally in a WPFform. 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!

Nikhil G
  • 1,536
  • 3
  • 13
  • 28
  • @Sinatr Is this comment hints about the solution in the form of Attached behavior or a discussion further? – Nikhil G May 22 '19 at 12:43
  • 1
    You say "better", which implies approach is working. But how better? Is [this](https://stackoverflow.com/a/1356781/1997232) better? – Sinatr May 22 '19 at 13:56
  • Oh, I got it now! Though, I want guidance to do this task of throwing focus. I have improved my question. I hope, you may provide me your valuable guidance to solve this puzzle, now. – Nikhil G May 22 '19 at 14:16
  • 1
    Have you tried `BindingPriority` [MSDN](https://learn.microsoft.com/en-us/dotnet/framework/wpf/data/how-to-implement-prioritybinding)? – XAMlMAX May 22 '19 at 14:49

0 Answers0