Override System.Windows.Interactivity.EventTrigger
for capturing message for example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
public class EventTrigger : System.Windows.Interactivity.EventTrigger { #region CaptureEvent (DP SHORT) public bool CaptureEvent { get { return (bool)GetValue(CaptureEventProperty); } set { SetValue(CaptureEventProperty, value); } } public static readonly DependencyProperty CaptureEventProperty = DependencyProperty.Register("CaptureEvent", typeof(bool), typeof(EventTrigger), new PropertyMetadata(false)); #endregion protected override void OnEvent(EventArgs eventArgs) { if (eventArgs is RoutedEventArgs) { (eventArgs as RoutedEventArgs).Handled = CaptureEvent; } base.OnEvent(eventArgs); } } |
if you have a rectangle in dockpanel and you want to capturing MouseEvent, on clicking on rectangle the event if is not captured is transmited to Panel …
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<DockPanel Background="Red" LastChildFill="False" Margin="0,10,10.4,10.4" HorizontalAlignment="Right" Width="186" Grid.RowSpan="2"> <Rectangle Fill="Green" DockPanel.Dock="Top" Height="50"> <interactivity:Interaction.Triggers> <local:EventTrigger EventName="MouseDown" CaptureEvent="True"> <interactivity:InvokeCommandAction Command="{Binding ClickCommand, ElementName=win}" CommandParameter="{x:Null}" /> </local:EventTriggerExtended> </interactivity:Interaction.Triggers> </Rectangle> <interactivity:Interaction.Triggers> <local:EventTrigger EventName="MouseDown"> <interactivity:InvokeCommandAction Command="{Binding Click2Command, ElementName=win}" CommandParameter="{x:Null}" /> </local:EventTriggerExtended> </interactivity:Interaction.Triggers> </DockPanel> |
white this extend you can capture event on rectangle for not transmiting to parent … (available only for bubble strategy routed event)
Categories: Non classé
Commentaires récents