当用户点击按钮时,我在网格中显示TestControl:
<Grid>
<myControls:TestControl Panel.ZIndex="2" Visibility="Collapsed" Width="100" Height="100" />
<Button "Open Test Control" Click="btnOpen_Click" />
</Grid>
当用户在此控件外点击时,如何隐藏TestControl?
答案 0 :(得分:2)
您可以处理PreviewMouseLeftButtonDown
的{{1}}事件:
Grid
<Grid Background="Transparent" PreviewMouseLeftButtonDown="Grid_PreviewMouseLeftButtonDown">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<myControls:TestControl x:Name="tc" Visibility="Collapsed" Width="100" Height="100" />
<Button Content="Open Test Control" Click="btnOpen_Click" Grid.Row="1" />
</Grid>
答案 1 :(得分:0)
Haven没有尝试过,但LostFocus event可能是一种方法,因为你在显示后将焦点设置到测试控件上。