我是 WPF 新手,正在创建一个简单的应用程序。基本上,该应用程序显示一个人的年龄。我为此使用了两个窗口。第一个窗口将出生日期作为输入,第二个弹出窗口显示他当前的年龄。现在我想要的是对显示年龄的弹出窗口应用一些简单的过渡效果。它可能是任何无关紧要的效果。下面是主窗口的 c# 代码。
namespace WpfApplication6
{
public partial class MainWindow : Window
{
int year;
public MainWindow()
{
InitializeComponent();
string n = DateTime.Now.ToString();
}
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string yearlist = comboBox3.SelectionBoxItem.ToString();
string date = comboBox1.SelectionBoxItem.ToString();
string month= comboBox2.SelectionBoxItem.ToString();
if (date == "DD")
{ MessageBox.Show("Select date"); }
else
{
if (month == "MM")
{ MessageBox.Show("Select month"); }
else
{
if (yearlist == "YYYY")
{ MessageBox.Show("Select year"); }
else
{
System.DateTime dob = new System.DateTime(Convert.ToInt16(comboBox3.SelectionBoxItem), Convert.ToInt16(comboBox2.SelectionBoxItem), Convert.ToInt16(comboBox1.SelectionBoxItem), 12, 0, 0);
System.TimeSpan diff = DateTime.Now.Subtract(dob);
year = (Convert.ToInt32(diff.Days) / 365);
int days = (Convert.ToInt32(diff.Days) % 365);
string str = string.Format("Age is:{0} years and {1} days", year, days);
newwindow nw = new newwindow(str);
nw.Show();
}
}
}
}
private void comboBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
现在弹出窗口的代码
namespace WpfApplication6
{
public partial class newwindow : Window
{
public newwindow(string strmsg)
{
InitializeComponent();
label1.Content = strmsg;
}
private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
}
}
}