2012-06-30 81 views
0

当鼠标不在窗口中时,我有一个窗口会淡出。 我创建了一个弹出窗口,显示(在窗口边界内),当我点击一个按钮。 但是 - 当我将鼠标移到弹出窗口上 - 我的窗口淡出? 我能做些什么,所以当我弹出窗口时,窗口不会淡出?弹出窗口和一个鼠标退出窗口

淡出代码 空隙gridFadeOutStoryBoard_Completed(对象发件人,EventArgs的) { CloseWindow(); }

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> 

在先进的感谢, 锭..

+0

请提供一些代码。 –

+0

Popup本身是另一个窗口,这是造成问题。 – Dusan

+0

这就是我正在想..我需要弹出(因为它漂浮)..是不是有解决我的问题? – dinbrca

回答

2

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

+0

谢谢..这个伎俩 – dinbrca