이러한 이벤트를 수동으로 발생시키는 자식 컨트롤을 사용하여 라우트 된 이벤트를 얻으려고하면 주 모눈 수준에서 거품이 생겨 처리됩니다. 기본적으로 내가 이런 걸하고 싶지 :WPF 라우팅 이벤트, 사용자 지정 이벤트 구독
<Grid Name="Root" WpfApplication5:SpecialEvent.Tap="Catcher_Tap">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<WpfApplication5:UserControl2 Grid.Row="0" x:Name="Catcher" />
<WpfApplication5:UserControl1 Grid.Row="1" />
<Frame Grid.Row="2" Source="Page1.xaml" />
</Grid>
을하지만 내 예를 실행할 때, 나는 프리젠 테이션 프레임 워크에서 null 참조를 얻을, 응용 프로그램은 (/를 XAML을 초기화로드하려고 할 때 실패, 초기화되지 않습니다 InitializeComponent()). 나는 기본적으로 ButtonBase.Click은 부모가 어떤 버튼 클릭으로 자신의 아이들을위한() 메소드를 구독 할 수 있습니다 방법의 동작을 복사 걸려
public class SpecialEvent
{
public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent(
"Tap", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(UserControl1));
// Provide CLR accessors for the event
public event RoutedEventHandler Tap;
}
: 여기에 이벤트를 포함하는 작은 파일입니다. 그러나 이것은 ButtonBase.Click() 이외에는 작동하지 않는 것 같습니다. 즉, 내 사용자 정의 WpfApplication5:SpecialEvent.Tap="Catcher_Tap"
을 ButtonBase.Click="Catcher_Tap"
으로 전환하면 작동합니다. 어떤 아이디어? ButtonBase는 내가하지 않는 일을 무엇입니까? 당신이하는대로 XAML에서 지정,
public MainWindow()
{
InitializeComponent();
Root.AddHandler(SpecialEvent.TapEvent, new RoutedEventHandler(Catcher_Tap));
}
어떤 이유 :