单击窗口中的按钮会传播到下面的窗口

时间:2019-03-25 12:21:48

标签: wpf user-interface events

也许有人遇到了这个问题。 我有一个创建的屏幕保护程序窗口。当我触摸此屏幕保护程序时,它将关闭。在屏幕保护程序下,我有一个带有按钮的窗口。

当我单击屏幕保护程序时,屏幕保护程序已关闭,但也按下了下方窗口中的按钮。

我正在捕获屏幕保护程序窗口的keydown事件,然后正在执行close();

有什么想法可以阻止它发生吗?

下面的窗口中被按下但我不想被按下的按钮具有以下样式:

<Style x:Key="ButtonRoundWithArrow" TargetType="{x:Type Button}">
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
        <Setter Property="Background" Value="{StaticResource RadioButton.Static.Background}" />
        <Setter Property="BorderBrush" Value="{StaticResource RadioButton.Static.Border}" />
        <Setter Property="Foreground" Value="#FF2296CF" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True" Cursor="Hand">
                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="Normal" />
                                <vsm:VisualState x:Name="MouseOver" />
                                <vsm:VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetProperty="(TextElement.FontFamily)"
                                            Storyboard.TargetName="textBlock">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <FontFamily>Roboto</FontFamily>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames
                                            Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)"
                                            Storyboard.TargetName="textBlock">
                                            <EasingColorKeyFrame KeyTime="0" Value="#FF2BC0E8" />
                                        </ColorAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames
                                            Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)"
                                            Storyboard.TargetName="__">
                                            <EasingColorKeyFrame KeyTime="0" Value="#FF2BC0E8" />
                                        </ColorAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background)"
                                                                       Storyboard.TargetName="border">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <SolidColorBrush Color="White" />
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Disabled" />
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>
                        <Border x:Name="border" BorderBrush="{DynamicResource BrushLightBlue}"
                                HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch" Width="Auto"
                                BorderThickness="2" CornerRadius="13" Background="{DynamicResource BrushLightBlue}" />
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                            <TextBlock x:Name="textBlock" HorizontalAlignment="Center" TextWrapping="NoWrap"
                                       VerticalAlignment="Center" Text="{TemplateBinding Content}" Foreground="White"
                                       FontFamily="Roboto" FontSize="36" FontWeight="Normal" />
                            <TextBlock x:Name="__" HorizontalAlignment="Right" TextWrapping="NoWrap"
                                       VerticalAlignment="Center" Foreground="White" FontFamily="Roboto" FontSize="36"
                                       Margin="10,0,0,0" Text="" FontWeight="Normal" />
                        </StackPanel>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasContent" Value="true">
                            <Setter Property="FocusVisualStyle" Value="{StaticResource OptionMarkFocusVisual}" />
                            <Setter Property="Padding" Value="4,-1,0,0" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true" />
                        <Trigger Property="IsEnabled" Value="false" />
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="FontSize" Value="14" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="MinHeight" Value="32" />
        <Setter Property="Width" Value="380" />
        <Setter Property="Height" Value="118" />
    </Style>

0 个答案:

没有答案