I have a fairly complicated application that includes a RadDataForm that contains a TextBox that is supposed to allow a user to type multiple lines. The TextBox has TextWrapping="Wrap" and AcceptsReturn="True", but it doesn't work, of course, because RadDataForm binds the return key, and commits the form, regardless of what type of field has the focus.
So I wrote a simple DataFormCommandProvider:
public class ClearReturnKeyActionCommandProvider : DataFormCommandProvider{ public ClearReturnKeyActionCommandProvider() : base(null) { } public ClearReturnKeyActionCommandProvider(RadDataForm dataForm) : base(dataForm) { this.DataForm = dataForm; } public override List<DelegateCommandWrapper> ProvideCommandsForKey(KeyEventArgs args) { var actionsToExecute = base.ProvideCommandsForKey(args); if (args.Key == Key.Return) { actionsToExecute.Clear(); } return actionsToExecute; }}Stick this in a resource, and set the form's CommandProvider, and suddenly I can enter multiple lines in the TextBox:
<telerik:RadDataForm Grid.Row="1" Grid.Column="0" ItemsSource="{Binding Path=viewModel.contacts, RelativeSource={RelativeSource AncestorType=KtWpf:ContactsControl}}" AutoGenerateFields="False" EditTemplate="{StaticResource contactsEditTemplate}" NewItemTemplate="{StaticResource contactsEditTemplate}" ReadOnlyTemplate="{StaticResource contactsEditTemplate}" AutoEdit="False" CommandButtonsVisibility="None" CommandProvider="{StaticResource clearReturnKeyActionCommandProvider}" InitializingNewItem="radDataForm_InitializingNewItem" EditEnding="radDataForm_EditEnding" />And, of course, something else breaks.
I have a pair of save and cancel buttons, outside the form, that set RadDataFormCommands.CommitEdit and RadDataFormCommands.CancelEdit.
<telerik:RadButton Style="{StaticResource actionButton}" Content="Save" Command="telerik:RadDataFormCommands.CommitEdit" CommandTarget="{Binding ElementName=radDataForm}"/><telerik:RadButton Style="{StaticResource actionButton}" Content="Cancel" Command="telerik:RadDataFormCommands.CancelEdit" CommandTarget="{Binding ElementName=radDataForm}" />When I do not have the CommandProvider set, these work fine. But when I do, they're disabled. Both of them are disabled, even the Cancel button, which isn't ever supposed to be disabled.
This should be simple. What am I doing wrong?