MVVM シナリオで TreeView を使用しています。子 TreeViewItem の表示とコンテキスト メニューはビュー モデルのタイプに依存するため、データ テンプレートを使用して、表示する適切な UserControl を選択しています (StyleSelector よりも管理がはるかに簡単です)。
私の問題は、 UserControl がその表面のどこかでクリックされたときにコマンドを処理する必要があることです。UserControl に直接アタッチされた EventTrigger を使用しましたが、クリック イベントはTextBlock または Imageのテキストをクリックしたときにのみ処理されます。サンプルコードは次のとおりです。
<UserControl x:Class="FolderTreeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding Path=DisplayCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Path=Icon}"/>
<TextBlock Text="{Binding Path=DisplayName}"/>
</StackPanel>
</UserControl>
これを機能させることができるという考えはありますか?