Update 2010 06 12
Distill the essence into a smaller selection - the solution is available here http://db.tt/v6r45a4
Now the problem seems to be related to the tab control: When the data context is reapplied (click the button), everything seems to work as expected. Binding updates, but then all the bindings on the active tab are broken.
You can verify this by selecting any tab and clicking the button, you will see the controls on this go kaput tab. A bunch of registration operators were added, as a result of which my friend came to this resume and corrected it [Set DataContext = "{Binding}" in the tab control]
But we are still not sure why this behaves the way it does ...
TabControl Data Context now set to ReproTabItemBug.MainViewModel
TabPage [LeftTabPage] Data Context now set to ReproTabItemBug.LeftViewModel
System.Windows.Data Error: 40 : BindingExpression path error: 'MiddleProp' property not found on 'object' ''MainViewModel' (HashCode=50608417)'. BindingExpression:Path=MiddleProp; DataItem='MainViewModel' (HashCode=50608417); target element is 'TextBox' (Name='MiddleTabTextbox'); target property is 'Text' (type 'String')
TabPage [MiddleTabPage] Data Context now set to ReproTabItemBug.MiddleViewModel
Middle tab textbox text changed to 634272638824920423
TabPage [RightTabPage] Data Context now set to ReproTabItemBug.RightViewModel
Middle tab textbox text changed to
Previous post
(Disclaimer: long post ahead ... get your popcorn. I spent most of the day on this ..)
My ViewModel consists of three POCO subViewModels. Each subVieModel has properties that are related in the three sections mentioned above. Each subViewModel is displayed as a standard get-get.net property (No INotifyPropertyChanged)
My view has 3 sections. Each section has a DataContext tool like this.
...
<TabItem x:Name="_tabPageForVM2" DataContext="{Binding PropReturningSubVM2}">
</TabItem>
...
So, to summarize
<MainView>
<Control DataContext="{Binding PropReturningSubVM1}" >.. Section1 .. </Control>
<Control DataContext="{Binding PropReturningSubVM2}" >.. Section2 .. </Control>
<Control DataContext="{Binding PropReturningSubVM3}" >.. Section3 .. </Control>
</MainView>
Now here is the cryptic bit. On normal startup, I create an instance of MainViewModel (which has child view models passed to its ctor). The properties in the viewport confirm this.
Trace.WriteLine("Before setting datacontext");
mainView.DataContext = null;
mainView.DataContext = mainViewModel;
Trace.WriteLine("After setting datacontext");
. - , , , , . , , , datacontext ( , )
, DataContext=mainViewModel, . , ( ) . 2 - .
System.Windows.Data Error: 40 : BindingExpression path error: 'RphGaugeMaxScale' property not found on 'object' ''MainViewModel' (HashCode=38546056)'. BindingExpression:Path=RphGaugeMaxScale; DataItem='MainViewModel' (HashCode=38546056); target element is 'Gauge' (Name='GaugeControl'); target property is 'MaxValue' (type 'Double')
System.Windows.Data Error: 40 : BindingExpression path error: 'RphGaugeMaxScale' property not found on 'object' ''MainViewModel' (HashCode=38546056)'. BindingExpression:Path=RphGaugeMaxScale; DataItem='MainViewModel' (HashCode=38546056); target element is 'Gauge' (Name='GaugeControl'); target property is 'MajorTickCount' (type 'Int32')
...
SubViewModel2, MainViewModel.
MainView ( DataContext),
_tabPageForVM2.DataContext = null;
_tabPageForVM2.DataContext = mainVM.PropReturningSubVM2;
.
- subVM2? DataContext, ?
- tabPage {Binding}, , , "FullTypeNameOfSubVM2", , DataContext . , ?