DataFormCommandProvider disables RadDataFormCommands?

4 posts, 0 answers
  1. Jeff
    Jeff avatar
    100 posts
    Member since:
    Apr 2008

    Posted 19 Aug Link to this post

    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?

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 23 Aug Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jeff
    Jeff avatar
    100 posts
    Member since:
    Apr 2008

    Posted 23 Aug Link to this post

    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.

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 24 Aug Link to this post

    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.
Back to Top