This is a migrated thread and some comments may be shown as answers.

DataFormCommandProvider disables RadDataFormCommands?

3 Answers 44 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 19 Aug 2016, 08:19 PM

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?

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 23 Aug 2016, 10:02 AM
Hello,

I tried to reproduce the issue you've described in a sample project but was, unfortunately, unable to do so. Could you please have a look at the project I've attached to my reply and let me know whether I'm missing something important?

The behavior you've described seems expected from the code you provided as setting the AutoEdit property to False and the CommandButtonsVisibility to None means that there's no way for RadDataForm to get into Edit mode, so the buttons are bound to be disabled. That is why I've added an Edit button in my project to get RadDataForm into edit mode. The alternative to this would be to set the AutoEdit property to True.

Could you also confirm that simply removing the command provider results in the buttons getting enabled? If that is the case, please provide the contactsEditTemplate you've defined so that I may assist you further in finding a solution to this issue.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Jeff
Top achievements
Rank 1
answered on 23 Aug 2016, 02:49 PM

The form goes into edit mode because I'm calling BeginEdit().

I did confirm that removing the command provider resulted in the buttons being enabled.

I replaced the RadFormCommands with my own custom commands, and they did not have the issue.

0
Dilyan Traykov
Telerik team
answered on 24 Aug 2016, 08:37 AM
Hello Jeff,

Could you please clarify how and where you're calling the BeginEdit() method as calling it from RadDataForm's Loaded event as well as binding a button to the BeginEdit command successfully put RadDataForm into edit mode and enable the Save and Cancel buttons at my end?

I'm attaching a modified version of the project from my previous reply to demonstrate this. Could you please have a look at it and let me know how I should modify it in order to reproduce the behavior you're observing at your end?

Thank you in advance for your cooperation on the matter.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
DataForm
Asked by
Jeff
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or