sgonchar
Topic Author
Posts: 48
Joined: 15 Mar 2021, 22:11

SetFocusAction TargetName only works when inside the target

12 Apr 2021, 18:11

Hello,
I noticed that:
      <i:EventTrigger EventName="IsVisibleChanged">
        <noesis:SetFocusAction TargetName="SomeButton" />
      </i:EventTrigger>
Only works when is part of triggers for SomeButton, and not a panel, or another element.
I feel like I'm just doing something wrong ..

This works fine:
<StackPanel>
    <Button x:Name="SomeButton" Style="{StaticResource SomeButtonStyle}" >
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="IsVisibleChanged">
                <noesis:SetFocusAction TargetName="SomeButton" />  <!--  TargetName optional here -->
            </i:EventTrigger>
         </i:Interaction.Triggers>
    </Button>
</StackPanel>
This does not work:
<StackPanel
      <i:Interaction.Triggers>
           <i:EventTrigger EventName="IsVisibleChanged">
               <noesis:SetFocusAction TargetName="SomeButton" />
           </i:EventTrigger>
      </i:Interaction.Triggers>
    >
    <Button x:Name="SomeButton" Style="{StaticResource SomeButtonStyle}" >
    </Button>
</StackPanel>
What am I doing wrong?
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: SetFocusAction TargetName only works when inside the target

14 Apr 2021, 14:11

What is happening is that the IsVisibleChanged event is raised in the parent StackPanel before updating the visibility of the child Button, so when the SetFocusAction tries to set the focus on the Button it fails because it is still not focusable (not visible).

When moving the trigger to the Button, the IsVisibleChanged event is happening once the Button is visible and focusable, thus the action works as expected.

It has nothing to do with the TargetName property, because I can have another child inside the StackPanel after the Button with the trigger and SetFocusAction using the TargetName to point to the Button and it also works:
<StackPanel x:Name="LayoutRoot" Visibility="Hidden" HorizontalAlignment="Center" VerticalAlignment="Center">
  <Button x:Name="SomeButton" Content="Some Button" Margin="10"/>
  <Button x:Name="OtherButton" Content="Other Button" Margin="10"/>
  <Decorator>
    <i:Interaction.Triggers>
      <i:EventTrigger EventName="IsVisibleChanged">
        <noesis:SetFocusAction TargetName="SomeButton"/>
      </i:EventTrigger>
    </i:Interaction.Triggers>
  </Decorator>
</StackPanel>
 
sgonchar
Topic Author
Posts: 48
Joined: 15 Mar 2021, 22:11

Re: SetFocusAction TargetName only works when inside the target

15 Apr 2021, 16:59

Thank you, I never realized visible and triggers processing is sequential like that.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: SetFocusAction TargetName only works when inside the target

19 Apr 2021, 10:45

Yes, behaviors and triggers are attached to the associated object as they appear in the tree, so the registration of events follows the same order.

Who is online

Users browsing this forum: No registered users and 89 guests