How to attach a canexecute command to RadDataform button

9 posts, 1 answers
  1. Randy Hompesch
    Randy Hompesch avatar
    94 posts
    Member since:
    Nov 2008

    Posted 21 Feb 2018 Link to this post

    Hi,

    Can someone show me how to do this in an MVVM friendly way?

    I have want to set the ok button enabled state based on App.AppState.GetValue<bool>("IsReadOnlyUser");

    Normally, I would do this with the CanExecute portion of a delegate. I can't quick seem to figure out how to rig this up.

    I tried

    <telerik:EventToCommandBehavior.EventBindings>
        <telerik:EventBinding Command="{Binding DataContext.BeginningEditCommand, Mode=TwoWay,     UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}"
    EventName="BeginningEdit" PassEventArgsToCommand="True"     CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=telerik:GridViewRow} }"/>
    </telerik:EventToCommandBehavior.EventBindings>

    But couldn't find anything to set that would affect the ok button's IsEnabled.

    Any help would be great.

    Thanks... Ed

     

     

     

  2. Stefan
    Admin
    Stefan avatar
    1073 posts

    Posted 26 Feb 2018 Link to this post

    Hello Ed,

    Thank you for the provided code snippet.

    The enabled/disabled state of the commit button depends on the CanExecute of the CommitEdit command of RadDataForm. With this in mind, the approach for achieving any modifications of this default implementation would require editing the template of the control. Below you can find the default definition of the commit button.
    <StackPanel x:Name="PART_FooterPanel" Orientation="Horizontal" HorizontalAlignment="Right">
                           <telerik:RadButton x:Name="PART_CommitButton"
                                   MinWidth="48"
                                   MinHeight="20"
                                   Margin="2,4,4,4"
                                   Content="{TemplateBinding CommitButtonContent}"
                                   Command="{x:Static controls:RadDataFormCommands.CommitEdit}"/>
                           <telerik:RadButton x:Name="PART_CancelButton"
                                   MinWidth="48"
                                   MinHeight="20"
                                   Margin="2,4,4,4"
                                   Content="{TemplateBinding CancelButtonContent}"
                                   Command="{x:Static controls:RadDataFormCommands.CancelEdit}"/>
                       </StackPanel>

    As you can see, the Coomand of the Button executes the CommitEdit command of RadDataForm. Can you please clarify a bit what is the exact behavior you are aiming at? How exactly should the button behave and when should and edit be committed?

    Regards,
    Stefan
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Randy Hompesch
    Randy Hompesch avatar
    94 posts
    Member since:
    Nov 2008

    Posted 05 Mar 2018 in reply to Stefan Link to this post

    Hi,

    Thanks for the reply. Basically, I have a situation where there is a situation where, depending on circumstances, I need the RadDataForm to be read-only.

    Right now I am using the CommandButtonVisibility property to hide the commit button. It works, but I'd rather *disable* it than hide it.

    Thanks ... Ed

     

  4. Stefan
    Admin
    Stefan avatar
    1073 posts

    Posted 08 Mar 2018 Link to this post

    Hello Ed,

    For such requirement, you can try setting the IsEnabled property of RadDataForm to False. Can you please check it out? Note, that it will disable the whole control rather than the Commit button only. As mentioned in my previous reply, the states of the Commit button are controlled by the CanExecute of the CommitEdit command of the control.

    Best Regards,
    Stefan
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Randy Hompesch
    Randy Hompesch avatar
    94 posts
    Member since:
    Nov 2008

    Posted 09 Mar 2018 in reply to Stefan Link to this post

    I tried the IsEnabled as you suggested. Not tasty because it greys out the entire form and makes it hard for users to read. How can I subclass the CanExecute of the commitedit command? I'd really like to just grey out the commit button.

    Thanks ... Ed

     

  6. Stefan
    Admin
    Stefan avatar
    1073 posts

    Posted 14 Mar 2018 Link to this post

    Hi Ed,

    Modifying the already implemented CommitEdit command would not be possible. You can either define a custom Command and bind it to the CommitButton, or you can alter the IsEnabled property of the button. If the IsEnabled property of the button is set to false, it will be disabled irrelevant to the value of the CanExecute of the command.

    Hope this helps.

    Regards,
    Stefan
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  7. Randy Hompesch
    Randy Hompesch avatar
    94 posts
    Member since:
    Nov 2008

    Posted 15 Mar 2018 in reply to Stefan Link to this post

    Hi,

    Thanks. The only question left, is, given a RadDataForm named myForm, how to get to the button to disable it? I guess I'm asking for a snippet that shows me myForm.obj.obj.THEBUTTON.IsEnabled = false. It's the "obj.obj.THEBUTTON" that I need help filling in. :-)

    Thanks ... Ed

     

     

  8. Answer
    Stefan
    Admin
    Stefan avatar
    1073 posts

    Posted 19 Mar 2018 Link to this post

    Hi Ed,

    Generally, the recommended approach is to apply such modifications in the template of the control. However, since you need to achieve this programmatically, you can use a logic similar to the one shown below.
    this.dataForm.ChildrenOfType<RadButton>().Where(b => b.Name == "PART_CommitButton").FirstOrDefault().IsEnabled = false;

    Have a nice week, Ed.

    Regards,
    Stefan
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  9. Randy Hompesch
    Randy Hompesch avatar
    94 posts
    Member since:
    Nov 2008

    Posted 29 Mar 2018 in reply to Stefan Link to this post

    That's the magic sauce I was looking for!

    Thanks.

Back to Top