我一直在尝试创建一个通知窗口, 但我正在努力弄清楚为什么在我运行时不发生这种不透明的变化。 相反, 窗口会停留一秒钟, 然后关闭而没有任何明显的变化。 我通过其他方法所做的其他尝试都失败了, 所以这一定是我缺少的一些属性。 感谢您的帮助!
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>