我有以下边框:
<Border CornerRadius="10,10,0,0" Height="23"
HorizontalAlignment="Center"
VerticalAlignment="Center"
BorderBrush="DarkBlue"
BorderThickness="1"
Background="AntiqueWhite">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center">
<Image Source="/Resources/Info_48.png"
Height="20"
Width="20"
Stretch="Fill"/>
<TextBlock Width="90"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Background="Transparent"
FontSize="12">
<Run Text="This is a Popup simulation"/>
</TextBlock>
</StackPanel>
</Border>
显示面板时,此边框可见。显示边框和子组件后,单击鼠标时,它们将自动隐藏在窗口中的任何位置。
我正在尝试做的是检测 boder 及其子组件之外的鼠标单击事件。一旦在外面检测到单击,我需要隐藏边框及其子组件,类似于 StaysOpen=false 时的弹出窗口,并且在鼠标单击时会自动隐藏。
如何检测控件外部的鼠标单击?
将边框样式设置为可见或通过更改颜色等隐藏边框。
<Border Background="Transparent"
Height="18" Width="18">
<Border.Style>
<Style Target-type="Border">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="visibility" Value="false" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>