Question: In my XAML, I have this property, which works like a charm :

```
DataContext="{Binding Chat, Source={StaticResource Locator}}"

```

It is binded correctly, showing design time data etc.

However now I need to get data from textBox :

```
     <TextBox Text="{Binding MessageInput, Mode=TwoWay}"/>

```

And I do not know, how to access this textBox (or binded MessageInput string) from code behind.

Answer: 
The ugly way:

```
string res = (DataContext as [TypeOfYourViewModel]).MessageInput;

```

A little better way:

```
<TextBox Name="tbMessageInput" ...>

```

and

```
string res = tbMessageInput.Text

```
if you need to access the textproperty then you can create a reference to the viewmodel and obtain the text from there. You can replace the chatViewModel with your viewmodel in my code

```
private string GetText()
{
    ChatViewModel vm = this.DataContext as ChatViewModel;

    if(vm != null)
        return vm.MessageInput;
     else
        return string.Empty;
}

```