---
title: "Textbox KeyBinding with AcceptsReturn = true"  
description: "Textbox KeyBinding with AcceptsReturn = true"  
author: "Anonymous User"  
published: 2013-09-04  
updated: 2013-09-04  
canonical: https://www.mindstick.com/forum/1456/textbox-keybinding-with-acceptsreturn-true  
category: "c#"  
tags: ["c#", "KeyBinding", "Textbox", "Textbox KeyBinding", "free open source", "mindstick"]  
reading_time: 1 minute  

---

# Textbox KeyBinding with AcceptsReturn = true

Basically I have a [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) which will [accept](https://yourviews.mindstick.com/view/81278/we-have-to-accept-that-roger-federer-is-the-richest-one) return when a [checkbox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net) is unchecked and when it's checked I want the textbox to [react](https://www.mindstick.com/articles/327892/react-why-it-just-makes-sense-for-web-development) on KeyBinding I wrote.

<TextBox AcceptsReturn="{[Binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp) IsChecked, ElementName=EnterCheckbox, Converter={StaticResource InvertBooleanConverter}}" >

<TextBox.InputBindings>

<KeyBinding Key="Enter" [Command](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net)="{Binding CmdEnterPressed}"/>

</TextBox.InputBindings>

</TextBox >

[Now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now) in any cases, despite of fact that TextBox.AcceptsReturn is set to [True](https://yourviews.mindstick.com/view/81326/boycott-chinese-products-dream-will-come-true) when I press [Return] KeyBinding is firing and I want not to [fire](https://yourviews.mindstick.com/view/81364/assam-oil-well-fire-accident-why-we-are-prone-to-it) it but to go to next line of TB.

## Replies

### Reply by Sumit Kesarwani

Hi Samuel,\

You can implement CanExecute for that command like this:

```
public bool CanExecute(object parameter){    bool acceptReturns
= (bool)parameter;    return
!acceptReturns;}
```

And in your XAML (as far as CommandParameter is used for both Execute and CanExecute methods):

```
<KeyBinding Key="Enter" Command="{Binding
CmdEnterPressed}"                        
CommandParameter="{Binding RelativeSource={RelativeSourceMode=FindAncestor,
AncestorType={x:Type TextBox}}, Path=AcceptsReturn}"/>
```


---

Original Source: https://www.mindstick.com/forum/1456/textbox-keybinding-with-acceptsreturn-true

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
