I am writing a WPF page to update data stored on an SQL server, and the way I am writing it requires a copy of the original data to be stored to create a WHERE clause.
So, what I am trying to do is have two copies of the data stored in variables on the page. One that remains as the original object and one that is to be used as the data binding context which are declared like so:
public Object Current { get; set; }
private readonly Object Start = new Object();
Which in my constructor are declared as:
public PageUpdate(Object source) {
InitializeComponent();
Current = source;
Start = source;
}
If my understanding of data binding is correct, the data binding should be entirely unable to see the Start object.
I have tried several approaches, including setting the data context with DataContext = Current;
, using XAML to describe it in two different ways:
<TextBox x:Name="TextBox1" Text="{Binding Object.ObjectTextProperty, RelativeSource={RelativeSource FindAncestor AncestorType=Page}" />
<Page d:DataContext="{d:DesignInstance Type=Object}">
<TextBox x:Name="TextBox1" Text="{Binding ObjectTextProperty}" />
</Page>
And finally attempted to set each binding property in code-behind:
TextBox1.SetBinding(TextBox.TextProperty, new Binding("ObjectTextProperty")
{
BindingGroupName = "bindingGroup",
Source = Current,
Mode = BindingMode.TwoWay
});
And various combinations of the above.
Each time I've used this, I've tested by printing Start and Current to the debug console after editing the data from the front end and it always shows both objects as identical even though as far as I know, Start should never be altered by the data binding.
Am I missing something obvious here or should I just take a different approach?