我一直在尝试创建一个通知窗口,但我正在努力弄清楚为什么在我运行它时没有发生这种不透明度变化。相反,窗口将保持一秒钟然后关闭而没有任何可见的变化。我通过其他方法进行的所有其他尝试也都失败了,所以它一定是我缺少的一些属性。谢谢你的帮助!
public void RunForm(string error, MessageBoxIcon icon, int duration)
{
lblMessage.Text = error;
Icon i = ToSystemIcon(icon);
if (i != null)
{
BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(i.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
imgIcon.Source = bs;
}
this.WindowStartupLocation = WindowStartupLocation.Manual;
this.Show();
this.Left = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - this.RestoreBounds.Width - 20;
this.Top = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom - this.RestoreBounds.Height - 20;
while (this.Opacity > 0)
{
this.Opacity -= 0.05;
Thread.Sleep(50);
}
this.Close();
}
<Window Width="225" Height="140" VerticalContentAlignment="Center" HorizontalAlignment="Center" ShowActivated="True" ShowInTaskbar="False"
ResizeMode="NoResize" Grid.IsSharedSizeScope="False" SizeToContent="Height" WindowStyle="None" BorderBrush="Gray"
BorderThickness="1.5" Background="White" Topmost="True" AllowsTransparency="True" Opacity="1">
<Grid Height="Auto" Name="grdNotificationBox" >
<Image Margin="12,12,0,0" Name="imgIcon" Stretch="Fill" HorizontalAlignment="Left" Width="32" Height="29" VerticalAlignment="Top" />
<TextBlock Name="lblMessage" TextWrapping="Wrap" Margin="57,11,17,11"></TextBlock>
</Grid>