Update UC''s DataContext from within, TextBox binding gets lost
I have a user control that acts as a selection of a child object. The page has a data context which is the parent object - lets say a Person. I set my user control's data context to Person.Company. My user control will change the Data Context it is bound to - basically change to a different Company. And the TextBox in the user control is set to the Text DependencyProperty of the User Control - which is bound to Company.Name. Here's some code...
User Control:
<UserControlx:Class="MyTestInfragisticsXBAP.Lookup" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyTest" x:Name="root" > <Grid> <Grid.ColumnDefinitions> <ColumnDefinitionWidth="50"/> <ColumnDefinitionWidth="Auto"/> </Grid.ColumnDefinitions> <TextBoxName="LookupTextBox"Text="{Binding Text, ElementName=root}"></TextBox> <ButtonGrid.Column="1"Click="ChangeSource">Lookup</Button> </Grid> </UserControl>
The code behind just defines the Text DependencyProperty and the ChangeSource just creates a new Company and does this.DataContext = newCompany;
The Page just has the userControl (and some other controls to verify things work, but it's mainly this:
<local:LookupGrid.Column="1"Grid.Row="2"DataContext="{Binding Path=Editors, Mode=TwoWay}"Text="{Binding Name}"/>
I set the DataContext of the page in the code behind. Everything works except when you modify the value in the UC's TextBox. Then the binding gets lost. I think I've tried every possible combination of binding Modes and that didn't work. I tried ClearValue of the Text DP and that literally sets the value to a blank string and it never regains the binding value. The TextBox value should really only be bound one way, and it should always get what the UC's datacontext is after it changes. I don't understand why changing the value in the TextBox breaks the binding. Can anyone help?

