我一直在尝试创建通知窗口,但我一直在努力弄清楚为什么在运行它时不会发生这种不透明度偏移。相反,窗口将保持一秒钟,然后关闭而没有任何可见的变化。我通过其他方法所做的其他尝试都失败了,所以它一定是我遗失的一些财产。谢谢你的帮助!更改不透明度时重绘窗口不透明度
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>
谢谢。我今天遇到了WCF的单线程问题。我已经结束了与ShowDialog()和动画。 – Tim