It is not possible to reuse a single instance of Interaction.Triggers in a resource because it is attached to the control. This attachment becomes part of its state, so a single instance cannot be used by multiple controls.
You will need to include Interaction.Triggers in the template to create multiple instances. I think something like the following might work (warning air code).
<UserControl.Resources> <DataTemplate x:key="MyTextBox"> <TextBox> <i:Interaction.Triggers> <i:EventTrigger EventName="KeyDown"> <cal:ActionMessage MethodName="KeyPressed" /> </i:EventTrigger> </i:Interaction.Triggers> </TextBox> </DataTemplate> </UserControl.Resources>
...
<ContentPresenter x:Name="FirstName" Grid.Row="1" Grid.Column="1" ContentTemplate="{StaticResource MyTextBox}" /> <ContentPresenter x:Name="Initial" Grid.Row="1" Grid.Column="1" ContentTemplate="{StaticResource MyTextBox}" /> <ContentPresenter x:Name="LastName" Grid.Row="1" Grid.Column="1" ContentTemplate="{StaticResource MyTextBox}" />
It is my opinion that this kind of thing is not worth it. Triggers interaction stuff is really aimed at empowering the designer, not the developer. The designer is not worried that there is repetition in the "code".
source share