0
MVVM 시나리오에서 TreeView를 사용하고 있습니다. 자식 TreeViewItem의 표시 및 컨텍스트 메뉴는 뷰 모델의 유형에 따라 다르므로 데이터 템플릿을 사용하여 표시 할 올바른 UserControl을 선택합니다 (StyleSelector보다 훨씬 관리하기 쉽습니다).전체 UserControl 화면에서 클릭 이벤트 처리
내 문제는 내가 UserControl 클릭 그 표면에 어디서나 명령을 처리해야한다는 것입니다. UserControl에 직접 연결된 EventTrigger를 사용했지만 Click 이벤트는 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>
이 기능을 사용할 수 있습니까?