0

In this page, you can add items. now you press "Save" to add another one. Heres the code:

private void Btn_Save_Click(object sender, RoutedEventArgs e)
{
  // Adding the item to DB and List      
  MainData.MainDataItem MDI_Temp = new MainData.MainDataItem();

  MDI_Temp.Int_AF = Convert.ToInt32(Tb_AF.Text);
  MDI_Temp.Int_HO = Convert.ToInt32(Tb_HO.Text);
  MDI_Temp.Int_ST = Convert.ToInt32(Tb_ST.Text);
  MDI_Temp.Int_STD = Convert.ToInt32(Tb_STD.Text);
  MDI_Temp.Int_DIA = Convert.ToInt32(Tb_DIA.Text);
  MDI_Temp.Int_ECK = Convert.ToInt32(Tb_ECK.Text);
  MDI_Temp.Int_MID = ((HelperClasses.Main_VM)this.DataContext).MDO_TmpStore.Int_ID;
  MDI_Temp.Str_Bauteil = Str_Bauteil;
  MDI_Temp.Str_Defekt = Str_Defekt;
  MDI_Temp.Str_Massnahme = Str_Massnahme;
  MDI_Temp.Str_Feld = Tb_Feld.Text;
  MDI_Temp.Str_Zeile = Tb_Zeile.Text;
  MDI_Temp.Int_Pos = Convert.ToInt32(Tb_Pos.Text);

  HelperClasses.SQL_Class.DBAddItem(MDI_Temp);

  // Navigate
  HelperClass.Navigate("pages/New_Item.xaml");
}

And this is the void in the helperclass:

public static void Navigate(string Str_Uri)
{
  ((MainWindow)Application.Current.Windows[0]).Fm_MainContainer.Source = new Uri(Str_Uri, UriKind.Relative);
}

The first time you click on Btn_Save the page reloads, the second time it onyl add the item

Damon_Kronski
  • 17
  • 1
  • 8
  • I guess you want to show the updated data after save. if so then perhaps data binding is what you are looking for. – pushpraj Jun 19 '14 at 07:26
  • possible duplicate of [Transitioning from Windows Forms to WPF](http://stackoverflow.com/questions/15681352/transitioning-from-windows-forms-to-wpf) – pushpraj Jun 19 '14 at 07:26
  • I try to add items to a list, which i Show after you leave this page... My real Problem is, it initialize this page only once... – Damon_Kronski Jun 19 '14 at 07:29
  • Yep this is what I understand from your issue, You may please refer to http://stackoverflow.com/questions/15681352/transitioning-from-windows-forms-to-wpf for the basics of binding. currently you are doing in a pretty old fashion, you need wpf approach. – pushpraj Jun 19 '14 at 07:33
  • I'm using binding the most time. Here (at this page) its not possible. And how would binding help to reload this page the second time?! – Damon_Kronski Jun 19 '14 at 07:38
  • You need not to reload the page when you use collection binding, Observable collection updates the items control for you, ie. list, data grid, combo etc. – pushpraj Jun 19 '14 at 07:39

1 Answers1

3

Another option is to create an overload of navigate in helper class

public static void Navigate(object target)
{
  ((MainWindow)Application.Current.Windows[0]).Fm_MainContainer.Content = target;
}

ans use this way

// Navigate
New_Item item = new New_Item();
HelperClass.Navigate(item);

this will ensure to have a new initialization every time

pushpraj
  • 13,458
  • 3
  • 33
  • 50
  • Thanks!! It Works!!! I don't know why I didnt came after it ^^ I used it the last time (/.\)... But I'm really interested, why the other way only works once.... – Damon_Kronski Jun 19 '14 at 07:41
  • other way depends on framework, WPF decides when and how to initialize and when to reuse, so difficult to control. also navigating to same target does not work as property value does not change hence no effect. – pushpraj Jun 19 '14 at 07:44