17,747
社区成员




<Window x:Class="TestForWpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="517" Width="842" Background="White" WindowStartupLocation="CenterScreen">
<Grid>
<Button Content="Pop up" Height="23" HorizontalAlignment="Left" Margin="58,38,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace aaa
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void InitializeComponent()
{
throw new NotImplementedException();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
PopupWindow win = new PopupWindow();
win.Show();
}
}
}
<Window x:Class="TestForWpf.PopupWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PopupWindow" Height="211" Width="401" ResizeMode="NoResize" WindowStyle="None" WindowStartupLocation="CenterScreen">
<Grid Background="#dedede" Height="152" Width="359">
<Label Margin="46,44,54,54" Height="40" Content="This is a self-closing window!" VerticalContentAlignment="Bottom" FontSize="18" FontWeight="Bold"></Label>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Timers;
using System.Windows.Threading;
namespace aaa
{
/// <summary>
/// Interaction logic for PopupWindow.xaml
/// </summary>
public partial class PopupWindow : Window
{
private Timer timer = new Timer(3000);
public PopupWindow()
{
InitializeComponent();
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.Start();
}
private void InitializeComponent()
{
throw new NotImplementedException();
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
timer.Stop();
Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate()
{
this.Hide();
});
}
}
}