これらのイベントを手動で起動する子コントロールで動作するルーティング イベントを取得しようとしています。これらのイベントはバブルアップし、メイン グリッド レベルで処理されます。私は基本的に次のようなことをしたい:
<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()) をロード/初期化しようとすると失敗します。イベントを含む小さなファイルは次のとおりです。
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 を使用して親が子の任意のボタン click() メソッドをサブスクライブできるようにする方法の動作をコピーしたいと考えています。しかし、これは ButtonBase.Click() 以外には機能していないようです。つまり、カスタムを切り替えるWpfApplication5:SpecialEvent.Tap="Catcher_Tap"
とButtonBase.Click="Catcher_Tap"
機能します。理由はありますか?ButtonBase は何をしていて、私はしていないのですか?