I am learning WPF data binding.I have the following scenario. This is my Form1.xaml.cs
ViewModel1 VM1;
ViewModel2 VM2;
Public Form1()
{
InitializeComponent();
VM1 = new ViewModel1();
VM2 = new ViewModel2;
this.DataContext=VM1;
}
Form1.Xaml This works fine(CurrentRec is the currently selected record from an ObservableCollection<> collection of VM1):
<TextBox x:Name="txtTest1" IsEnabled="{Binding CurrentRec.SearchFound}" Text="{Binding CurrentRec.Description1}"/>
This is not working.This second Textbox is bound to a property on the second ViewModel,ie VM2(CurrentRec here is the currently selected record from the ObservableCollection<> collection of VM2):
<TextBox x:Name="txtTest2" DataContext={Binding VM2} IsEnabled="{Binding CurrentRec.SearchFound}" Text="{Binding CurrentRec.Description2}"/>
i even tried this:
<TextBox x:Name="txtTest2" DataContext={Binding VM2.CurrentRec} IsEnabled="{Binding SearchFound}" Text="{Binding Description2}"/>
but that too hasn't worked for me so far.Plz help.