WPF提示框效果
WPF提示框效果
1,新建WPF应用程序
2,添加用户控件Message
3,在Message中编写如下代码
<Border x:Name="border" BorderThickness="3" Width="400" Height="60" CornerRadius="30" BorderBrush="Black" Background="#FF293546">
<TextBlock Height="35" Margin="0,10,20,5" VerticalAlignment="Top" FontSize="24" FontWeight="Bold" Foreground="#FF507750" Text="看看!我的提示框" Width="197"></TextBlock>
</Border>
4,在WindowMain的加载事件中编写如下代码
NameScope.SetNameScope(root, new NameScope());
Message m = new Message();
m.Name = "aa";
注册名称
root.RegisterName("aa", m);
m.SetValue(Canvas.TopProperty,50.0);
m.SetValue(Canvas.LeftProperty,20.0);
this.root.Children.Add(m);
//一个改变透明度的故事版
Storyboard sb = new Storyboard();
DoubleAnimation da = new DoubleAnimation();
da.To = 0;
da.Duration = TimeSpan.FromSeconds(5);
Storyboard.SetTarget(da,m);
Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
sb.Children.Add(da);
sb.Completed += new EventHandler(sb_Completed);
sb.Begin();
}
//动画执行完成后移除用户控件
private void sb_Completed(object sender,EventArgs e)
{
this.root.Children.RemoveAt(1);
}