2013-04-08 42 views
1

我遇到问题System.Windows.Interactivity.EventTrigger。当我的CustomControl是一些标准的WPF面板的子项时,它完美地工作,但是无论何时我将其放入我的CustomPanelControl中,Tap事件都不会订阅。如果我将CustomPanelControl的基类从FrameworkElement更改为Panel,那么它可以工作。我假设我需要实施一些东西,但是什么?System.Windows.Interactivity.EventTrigger和带有子项的自定义控件

CustomControl.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); 
    } 
} 
+1

如果它是一个小组,为什么不从小组获得? – 2013-04-08 15:10:33

+0

因为我不需要任何面板功能和开销。我使用WPF框架来托管通过API创建的第三方控件。我需要一个容器控件(工具栏),它可以有孩子(按钮,复选框等)。所有这些控件都不依赖于WPF视觉效果。 – jur 2013-04-09 06:50:10

回答