I've a Silverlight page using a MVVM behind it to handle all the data bits going on.
The data context is set for the page using:
DataContext="{Binding AddNewClientViewModel, Source={StaticResource ServiceLocator}}"
ServiceLocator being a service that allows me to create and inject the appropriate VM using an IoC container.
This all works fine.
Now I have a DataForm like so:
<df:DataForm CurrentItem="{Binding NewClient}" AutoGenerateFields="False" >
<df:DataForm.NewItemTemplate>
<DataTemplate>
<StackPanel>
<df:DataField>
<TextBox Text="{Binding ClientName}" />
</df:DataField>
<df:DataField>
<TextBox Text="{Binding Property_on_the_VM_not_on_NewClient}" />
</df:DataField>
</StackPanel>
</DataTemplate>
</df:DataForm.NewItemTemplate>
</df:DataForm>
OK, so this dataform binds to the NewClient property on my ViewModel. The first DataField binds to the NewClient.ClientName. The second DataField I'd like to bind to a property that hangs of the root ViewModel.
I know there is the 'Source' parameter that you can pass in when binding, if I had a static resource of the VM or similar I could point it to that, but I don't. How can I link this binding up with property on the parent VM?
Edit
After a post by Jobi below, I've tried the following:
<TextBox DataContext="{Binding DataContext, ElementName=root}" Text="{Binding MyProperty}" />
And my top level control:
x:Name="root"
DataContext="{Binding AddNewClientViewModel, Source={StaticResource ServiceLocator}}"
No dice with getting this to work...