12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using Microsoft.Xaml.Behaviors;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace PDF_Office.CustomControl.SystemControl
- {
- /// <summary>
- /// 用于辅助绑定ScrollChanged等不方便直接绑定command的系统
- /// </summary>
- public class RoutedEventTrigger : EventTriggerBase<DependencyObject>
- {
- RoutedEvent _routedEvent;
- public RoutedEvent RoutedEvent
- {
- get { return _routedEvent; }
- set { _routedEvent = value; }
- }
- public RoutedEventTrigger()
- {
- }
- protected override void OnAttached()
- {
- Behavior behavior = base.AssociatedObject as Behavior;
- FrameworkElement associatedElement = base.AssociatedObject as FrameworkElement;
- if (behavior != null)
- {
- associatedElement = ((IAttachedObject)behavior).AssociatedObject as FrameworkElement;
- }
- if (associatedElement == null)
- {
- throw new ArgumentException("Routed Event trigger can only be associated to framework elements");
- }
- if (RoutedEvent != null)
- {
- associatedElement.AddHandler(RoutedEvent, new RoutedEventHandler(this.OnRoutedEvent));
- }
- }
- void OnRoutedEvent(object sender, RoutedEventArgs args)
- {
- base.OnEvent(args);
- }
- protected override string GetEventName()
- {
- return RoutedEvent.Name;
- }
- }
- }
|