我有一个问题System.Windows.Interactivity.EventTrigger
。CustomControl
当 my是某个标准 WPF 面板的孩子时,它可以完美运行,但是每当我将它放在 myCustomPanelControl
中时,该Tap
事件就永远不会被订阅。CustomPanelControl
如果我将from的基类更改为FrameworkElement
,Panel
则它可以工作。我假设我需要实现一些东西,但是什么?
自定义控件.cs:
public class CustomControl: FrameworkElement
{
public void RaiseTap()
{
OnTap();
}
protected virtual void OnTap()
{
RaiseEvent(new RoutedEventArgs(TapEvent));
}
public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent("Tap", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(CustomControl));
public event RoutedEventHandler Tap
{
add { AddHandler(TapEvent, value); }
remove { RemoveHandler(TapEvent, value); }
}
}
CustomPanelControl.cs:
[ContentProperty("Children")]
public class CustomPanelControl: FrameworkElement
{
public UIElementCollection Children { get; private set; }
public CustomPanelControl()
{
Children = new UIElementCollection(this, this);
}
}