SetFocusAction TargetName only works when inside the target
Hello,
I noticed that:
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:
This does not work:
What am I doing wrong?
I noticed that:
Code: Select all
<i:EventTrigger EventName="IsVisibleChanged">
<noesis:SetFocusAction TargetName="SomeButton" />
</i:EventTrigger>
I feel like I'm just doing something wrong ..
This works fine:
Code: Select all
<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>
Code: Select all
<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>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: SetFocusAction TargetName only works when inside the target
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:
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:
Code: Select all
<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>
Re: SetFocusAction TargetName only works when inside the target
Thank you, I never realized visible and triggers processing is sequential like that.
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: SetFocusAction TargetName only works when inside the target
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: Bing [Bot], Semrush [Bot] and 61 guests