Sending RoutedEvent from Code Behind for Custom UserControl
Hello! I have a custom user control defined as `MyScreen` with the the following RoutedEvent `InitialFocus`. I am struggling to set up the EventTrigger in XAML to successfully catch this routed event. What might be going wrong? Is this behavior supported?
Then in the xaml I have the following EventTrigger to listen for the routed event
When the RoutedEvent is triggered using the following line in the code behind it doesn't actually get caught by the EventTrigger in xaml and focus is not set:
Code: Select all
public partial class MyScreen: UserControl
{
public static readonly RoutedEvent InitialFocusEvent= EventManager.RegisterRoutedEvent(
"InitialFocusEvent", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(MyScreen));
public event RoutedEventHandler InitialFocus
{
add => AddHandler(InitialFocusEvent, value);
remove => RemoveHandler(InitialFocusEvent, value);
}
}
Code: Select all
<local:MyScreen>
<b:Interaction.Triggers>
<b:EventTrigger EventName="InitialFocus">
<noesis:SetFocusAction Engage="False" TargetName="MyButton"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</local:MyScreen>
Code: Select all
RaiseEvent(new RoutedEventArgs(InitialFocusEvent, this));-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Sending RoutedEvent from Code Behind for Custom UserControl
I think the problem is in the name used to register the event:
Compared to when you hook to the event in the trigger:
Could you try registering the event as "InitialFocus" instead?
Code: Select all
public static readonly RoutedEvent InitialFocusEvent= EventManager.RegisterRoutedEvent(
"InitialFocusEvent", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(MyScreen));Code: Select all
<b:EventTrigger EventName="InitialFocus">Re: Sending RoutedEvent from Code Behind for Custom UserControl
That was the issue! I was trying both ways but because of unrelated issues, noesis:SetFocusAction was not behaving as expected and I misidentified the problem.
Thank you!!
Thank you!!
Who is online
Users browsing this forum: No registered users and 5 guests