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

How to attach a canexecute command to RadDataform button

8 Answers 189 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Randy Hompesch
Top achievements
Rank 1
Randy Hompesch asked on 21 Feb 2018, 09:35 PM

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

 

 

 

8 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 26 Feb 2018, 04:24 PM
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.
0
Randy Hompesch
Top achievements
Rank 1
answered on 05 Mar 2018, 11:15 AM

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

 

0
Stefan
Telerik team
answered on 08 Mar 2018, 09:40 AM
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.
0
Randy Hompesch
Top achievements
Rank 1
answered on 09 Mar 2018, 11:08 AM

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

 

0
Stefan
Telerik team
answered on 14 Mar 2018, 08:56 AM
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.
0
Randy Hompesch
Top achievements
Rank 1
answered on 15 Mar 2018, 12:49 PM

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

 

 

0
Accepted
Stefan
Telerik team
answered on 19 Mar 2018, 04:05 PM
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.
0
Randy Hompesch
Top achievements
Rank 1
answered on 29 Mar 2018, 10:26 AM

That's the magic sauce I was looking for!

Thanks.

Tags
DataForm
Asked by
Randy Hompesch
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Randy Hompesch
Top achievements
Rank 1
Share this question
or