我有一个用户控件,其中有一个包含画布的控件模板:
<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>
As you can see the Canvas displays the object details when an object is selected - as defined in the Trigger. 当我单击对象外部的任何位置时,我希望画布变得不可见。我怎样才能做到这一点?