弹出窗口和鼠标褪色窗口

时间:2012-06-30 20:19:24

标签: c# wpf popup fadeout

当鼠标离开窗口时,我有一个淡出的窗口。 当我点击一个按钮时,我创建了一个弹出窗口(窗口边界内)。 但是 - 当我将鼠标移到弹出窗口时 - 我的窗口会淡出? 当我在弹出窗口时,我能做什么才能使窗口消失?

淡出代码     void gridFadeOutStoryBoard_Completed(object sender,EventArgs e)         {             关闭窗口();         }

    private void MainWindow_MouseLeave(object sender, MouseEventArgs e)
    {
        if (this.ResizeMode == System.Windows.ResizeMode.NoResize) // make sure fade out animation won't work when the window is fullscreen
        {
            if (!this.giveFirstTimeMouseLeave)
            {
                // Only start fading out if fully faded in, otherwise you get a flicker effect in the UX because the animation resets the opacity
                if (this.Opacity == 1)
                    gridFadeOutStoryBoard.Begin();
            }
        }
    }

淡出xaml代码:

<Storyboard x:Key="gridFadeOutStoryBoard">
        <DoubleAnimation Storyboard.TargetName="MyWin" BeginTime="0:0:0.5"
            Storyboard.TargetProperty="Opacity" From="1.00" To="0.75" AutoReverse="False" Duration="0:0:0.3" />
    </Storyboard>

弹出式xaml代码:

<Popup Name="FilterPopup" Width="200" Height="150" HorizontalAlignment="Left" Margin="0,36,0,0" IsEnabled="True" IsOpen="False">
            <Border BorderBrush="White" BorderThickness="3">
                <StackPanel Background="#FF333333" VerticalAlignment="Center" Height="200">
                    <StackPanel>
                        <Grid Margin="0,40,0,20">
                            <Grid.RowDefinitions>
                                <RowDefinition Height=" 30"></RowDefinition>
                                <RowDefinition Height="30"></RowDefinition>
                                <RowDefinition Height="30"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100"></ColumnDefinition>
                                <ColumnDefinition Width="100"></ColumnDefinition>
                                <ColumnDefinition Width="100"></ColumnDefinition>
                            </Grid.ColumnDefinitions>

                            <Label Name="lblPasswordReprint" Content="Password:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                            <TextBox Name="txtPasswordReprint" Width=" 90" Height="20" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" IsEnabled="True"/>

                            <Label Name="lblUserName" Content=" UserName:" HorizontalAlignment="Right" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" />
                            <TextBox Name="txtUserNameReprint" Width=" 90" Height=" 20" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left"/>

                            <Button Content="Reset" Width="70" Height="30" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" />
                            <Button Content="Save" Width="70" Height="30" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" />
                        </Grid>
                    </StackPanel>
                </StackPanel>
            </Border>
        </Popup>

先谢谢了, 嚣..

1 个答案:

答案 0 :(得分:2)

MainWindow_MouseLeave内你可以为FilterPopup.IsMouseOver添加额外的检查 - 这是真的然后跳过动画