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
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
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
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
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
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
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
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
That's the magic sauce I was looking for!
Thanks.