I've I really weird problem with my WPF / C# application. I've got a property which returns another property. Now I make a variable and set it to one of these properties. If I now change the value by binding, the variable is also changed.
To simplify it, here's the code:
Here's the first property:
public MainDataObject CmObj_Temp { get; set; }
Which is used here:
public MainDataObject CmObj_MainData { 
  get { 
    return TemporaryDataStore.CmObj_Temp; 
  } 
  set {
    TemporaryDataStore.CmObj_Temp = value;
    this.RaisePropertyChanged(() => this.CmObj_MainData);
  }
}
From which I set a variable here:
CmObj_Backup = TemporaryDataStore.CmObj_Temp;
or also like this (makes no different):
CmObj_Backup = ((VM)this.DataContext).CmObj_MainData;
And also use for binding here:
<TextBox Text="{Binding CmObj_MainData.Str_Internnr, Mode=TwoWay}"/>
Now if I change the text of the Textbox it also changes it here:
CmObj_Backup.Str_Internnr);
Can someone tell my why?
How can I change that?
Thx
This is an smaller form of my code:
public class DataObject 
{
  public string Str_Test1 {get; set;}
  public string Str_Test2 {get; set;}
  // --> Much more properties
}
public static class TempData 
{
  public static DataObject DObj1 {get;set;}
}
public class ViewModel
{
  public DataObject DObj2 {
    get {
      return TempData.DObj1;
    }
    set {
      TempData.DataObjet.DObj1 = value;
      this.RaisePropertyChanged(() => this.DObj2);
    }
}
public partial class MainWindow : Window
{
  public MainWindow()
  {
    var VM = new ViewModel();
    this.DataContext = VM;
  }
  public void SomeWhereInTheSoftware()
  {
    ((ViewModel)this.DataContext).DObj2.Str_Test1 = "Before";
    ObjBackup = ((ViewModel)this.DataContext).DObj2;
    ((ViewModel)this.DataContext).DObj2.Str_Test1 = "After";
    // --> Here is ObjBackup.Str_Test1 also "After"!!
  }
}
 
    