silverlight使用定时器右下角定时弹窗,模拟信息报警。
代码如下:
<Canvas VerticalAlignment="Bottom" HorizontalAlignment="Right">
<Canvas.Resources>
<Storyboard x:Name="storyPopUp">
<DoubleAnimation Duration="0:0:2" From="0" To="-200" Storyboard.TargetName="canvasPopup" Storyboard.TargetProperty="(Canvas.Top)" />
</Storyboard>
<Storyboard x:Name="storyPopDown">
<DoubleAnimation Duration="0:0:2" From="-200" To="0" Storyboard.TargetName="canvasPopup" Storyboard.TargetProperty="(Canvas.Top)" />
</Storyboard>
</Canvas.Resources>
<Canvas VerticalAlignment="Bottom" HorizontalAlignment="Right" x:Name="canvasPopup" Margin="-200 0 0 0" Width="200" Height="200">
<Border BorderThickness="1,1,1" Background="Azure" HorizontalAlignment="Right" VerticalAlignment="Top"
BorderBrush="Gold" Width="200" Height="200">
<Border.Effect>
<DropShadowEffect />
</Border.Effect>
<Grid>
<Grid.RowDeFinitions>
<RowDeFinition Height="15" />
<RowDeFinition Height="*" />
</Grid.RowDeFinitions>
<TextBlock Text="学习右下角弹窗" FontSize="12" FontWeight="Black" Foreground="Black" Grid.Row="0" />
<Border Background="White" Margin="0 5 0 0" CornerRadius="5" Grid.Row="1">
<TextBlock Text="弹窗显示内容!" Margin="3" textwrapping="Wrap" FontSize="12" Width="190" />
</Border>
</Grid>
</Border>
</Canvas>
</Canvas>
System.Windows.Threading.dispatcherTimer gapTimer;
void initAlarmTimer() { gapTimer = new System.Windows.Threading.dispatcherTimer(); gapTimer.Interval = new TimeSpan(0,10); gapTimer.Tick += new EventHandler(gapTimer_Tick); gapTimer.Start(); } void gapTimer_Tick(object sender,EventArgs e) { popAlarm(); } #region 报警信息 private void popAlarm() { storyPopUp.Begin(); alarmTitle.Text = "报警类型"; alarmContent.Text = "警情明细" + DateTime.Now.ToLongTimeString(); System.Windows.Threading.dispatcherTimer timer = new System.Windows.Threading.dispatcherTimer(); timer.Interval = new TimeSpan(0,4500); timer.Tick += new EventHandler((sender2,e2) => { storyPopUp.Stop(); storyPopDown.Begin(); timer.Stop(); }); timer.Start(); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。