Wpf 当单击对象以外的任何位置时,需要能够使控件模板内定义的画布不可见

Wpf 当单击对象以外的任何位置时,需要能够使控件模板内定义的画布不可见,wpf,wpf-controls,Wpf,Wpf Controls,我有一个用户控件,其中有一个包含画布的控件模板: <ControlTemplate x:Key="ListBoxItemTemplate" TargetType="ListBoxItem"> <Grid Width="30" Height="30"> <!-- IsHitTestVisible=False so you can

我有一个用户控件,其中有一个包含画布的控件模板:

<ControlTemplate x:Key="ListBoxItemTemplate"
                         TargetType="ListBoxItem">
            <Grid Width="30"
                  Height="30">
                <!-- IsHitTestVisible=False so you can select enemies when 
                the infotip is visible and overlaps other enemies
                -->
                <Canvas x:Name="Inspect"
                        Visibility="Collapsed"
                        IsHitTestVisible="False">
                    <Image Source="/Images/InspectBubble.png"
                           Width="250" />
                    <StackPanel Margin="20"
                                Width="200"
                                Orientation="Vertical">
                        <TextBlock Foreground="White"
                                   FontWeight="Bold"
                                   FontSize="9pt"
                                   Margin="2"
                                   Text="{Binding Path=PatientName}"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top"/>
                        <TextBlock Foreground="White"
                                   FontWeight="Bold"
                                   FontSize="9pt"
                                   Margin="2"
                                   Text="{Binding Path=Icu.IcuName}"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top"/>
                        <TextBlock Foreground="White"
                                   FontWeight="Bold"
                                   FontSize="9pt"
                                   Margin="2"
                                   Text="{Binding Path=Icu.IcuLocation}"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top"/>
                        <TextBlock Foreground="White"
                                   FontWeight="Bold"
                                   FontSize="9pt"
                                   Margin="2"
                                   Text="{Binding Path=AgeDisplay}"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top"/>
                        <TextBlock Foreground="White"
                                   FontWeight="Bold"
                                   FontSize="9pt"
                                   Margin="2"
                                   Text="{Binding Path=LOSDisplay}"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top"/>

                    </StackPanel>

                    <Canvas.RenderTransform>
                        <TranslateTransform X="-150"
                                            Y="-150" />
                    </Canvas.RenderTransform>
                </Canvas>

                <ContentPresenter RenderTransformOrigin="0.5,0.5">
                    <ContentPresenter.RenderTransform>
                        <RotateTransform Angle="{Binding Angle}" />
                    </ContentPresenter.RenderTransform>
                </ContentPresenter>
                <Grid.RenderTransform>
                    <TranslateTransform X="{Binding Location.X}"
                                        Y="{Binding Location.Y}" />
                </Grid.RenderTransform>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected"
                         Value="True">
                    <Setter Property="Visibility"
                            Value="Visible"
                            TargetName="Inspect" />
                    <Setter Property="Panel.ZIndex"
                            Value="1" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>


如您所见,画布在选择对象时显示对象详细信息-如触发器中所定义。当我单击对象之外的任何位置时,我希望画布变得不可见。我该怎么做?

惊讶……甚至没有一个答案……我的问题或……有什么问题吗。。。。没有答案有那么难吗?