2012-09-26 39 views
0

我是WPF的新手,正在創建一個簡單的應用程序。基本上應用程序顯示了一個人多大年紀。我爲此使用了兩個窗口。第一個窗口將D.O.B作爲輸入,第二個彈出窗口顯示當前的年齡。現在我想要的是將一些簡單的過渡效果應用於顯示年齡的彈出窗口。這可能是無關緊要的任何影響。以下是主窗口的c#代碼。wpf應用程序中兩個窗口之間的轉換效果

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) 
     { 

     } 
    } 
} 

回答

0

otherWindow.Opacity=0; 
otherWindow.Show(); 

和0將簡單的透明度動畫迭代1.將有效共創美好褪色。

DoubleAnimation da = new DoubleAnimation(); 
da.From = 1; 
da.To = 0; 
da.Duration = new Duration(TimeSpan.FromSeconds(2)); 
da.AutoReverse = true; 
da.RepeatBehavior = RepeatBehavior.Forever; 
// da.RepeatBehavior=new RepeatBehavior(3); 
rectangle1.BeginAnimation(OpacityProperty, da); 

看到http://tarundotnet.wordpress.com/2011/03/18/wpf-tutorial-change-opacity-using-animation/