Question: I have a simple WPF application. In the code behind I have an InputFile property like this.

```
    public string InputFile
    {
        get
        {
            return _inputFile;
        }
        set
        {
            _inputFile = value;
            OnPropertyChanged("InputFile");
        }
    }

```

Inside the XAML I have a StackPanel like this:

```
    <StackPanel Orientation="Horizontal" DataContext="{Binding Path=InputFile}">
        <StackPanel.CommandBindings>
            <CommandBinding Command="Open" 
                CanExecute="OpenCanExecute"
                Executed="OpenExecuted" />
            <CommandBinding Command="Select" 
                CanExecute="SelectCanExecute"
                Executed="SelectExecuted" />
        </StackPanel.CommandBindings>
        <TextBox Text="{Binding Path=.}"></TextBox>
        <Button Command="Select">...</Button>
        <Button Command="Open">-></Button>
    </StackPanel>

```

I need to keep the stackpanel datacontext linked to InputFile to allow the commands functions to access it.

Problem: when InputFile changes, the TextBox is updated but if I type a new value in the Textbox the property InputFile is not updated (setter method is not called). Any idea?

Answer: 
If your commands are the main reason to have the `DataContext` set like this, what about this solution?

```
<StackPanel Orientation="Horizontal">
    <StackPanel.CommandBindings>
        <CommandBinding Command="Open" 
            CanExecute="OpenCanExecute"
            Executed="OpenExecuted" />
        <CommandBinding Command="Select" 
            CanExecute="SelectCanExecute"
            Executed="SelectExecuted" />
    </StackPanel.CommandBindings>
    <TextBox Text="{Binding InputFile}"></TextBox>
    <Button Command="Select" CommandParameter="{Binding InputFile}">...</Button>
    <Button Command="Open" CommandParameter="{Binding InputFile}">-></Button>
</StackPanel>

```

if all else fails, this should always work. Its a nasty workaround but it should get the job done:

```
<Grid x:Name="myGrid">
    StackPanel Orientation="Horizontal" DataContext="{Binding Path=InputFile}">
        <StackPanel.CommandBindings>
            <CommandBinding Command="Open" 
                CanExecute="OpenCanExecute"
                Executed="OpenExecuted" />
            <CommandBinding Command="Select" 
                CanExecute="SelectCanExecute"
                Executed="SelectExecuted" />
        </StackPanel.CommandBindings>
        <TextBox Text="{Binding ElementName=myGrid, Path=DataContext.InputFile}"></TextBox>
        <Button Command="Select">...</Button>
        <Button Command="Open">-></Button>
    </StackPanel>
</Grid>

```

Like Tomtom already wrote, you might need the `UpdateSourceTrigger`.
You can bind directly to TextBox.
What is the point to bind to StackPanel if InputFile is string?

```
<StackPanel Orientation="Horizontal">
    <TextBox Text="{Binding InputFile}"></TextBox>
</StackPanel>

```

**Edit:**

You can bind command by using [FindAncestor](https://stackoverflow.com/a/1127964/667792 "FindAncestor"):

```
Command="{Binding RelativeSource={RelativeSource FindAncestor, 
AncestorType={x:Type Window}}, Path=DataContext.Select}"

```

Alternatively you can create custom type similar to this one:

```
public class InputFileViewModel
{
  string File {get; set;}
  ICommant Select {get; set;}
}

```

And then bind in TextBox to File property.