Reputation: 133
How do I get the content/text from a textbox using a binding? My textbox looks like this:
<TextBox x:Name="txtFields" Text="" Height="23" TextWrapping="Wrap"
Background="#FFCBEECD" AcceptsReturn="True" >
<TextBox.InputBindings>
<KeyBinding Key="Enter" Command="{Binding AddFieldCommand}"></KeyBinding>
</TextBox.InputBindings>
</TextBox>
As seen, I would like to receive the content/text from the textbox, when the user hits the enter-button.
Thanks,
Upvotes: 0
Views: 1062
Reputation: 8786
You need to define a property and bind it to your TextBox.Text
, something like:
ViewModel:
public string TextProperty {get; set;}
XAML:
<TextBox x:Name="txtFields" Text="{Binding TextProperty, UpdateSourceTrigger=PropertyChanged}".../>
And then you can access it (TextProperty
) from the AddFieldCommand
command.
Upvotes: 2