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

Custom Command Provider executing actions on View Model

4 Answers 102 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Antonio
Top achievements
Rank 1
Antonio asked on 14 May 2013, 04:08 PM
Hello,

I have a RadDataForm that is bound to a collection of records.  This form, when a record is edited should trigger an action in the view model that calls a web service to update the record in a downstream system.  My ultimate challenge is that I do not know how to refer back to the ViewModel (or if it is even possible) from the Custom Command provider.  Any help would be greatly appreciated!


Code Snippet from my XAML:

        <telerik:RadDataForm Header="Balance Inquiry"
                             x:Name="IcsManualOpDataForm"
                             AutoGeneratingField="IcsManualOpForm_AutoGeneratingField"
                             ItemsSource="{Binding BalanceInq}"
                             AutoGenerateFields="True">
            <telerik:RadDataForm.CommandProvider>
                <commandProvider:IcsManualOpCommandProvider DataForm="{Binding ElementName=IcsManualOpDataForm}"/>
            </telerik:RadDataForm.CommandProvider>
        </telerik:RadDataForm>


The Custome Command provider (called IcsManualOpCommandProvider) is defined as follows:
    public class IcsManualOpCommandProvider : DataFormCommandProvider
    {
        public IcsManualOpCommandProvider()
            : base(null)
        {
            
        }

        protected override void CommitEdit()
        {
            // TODO: call web service
           this.DataForm.CommitEdit();

        }
    }

4 Answers, 1 is accepted

Sort by
0
Antonio
Top achievements
Rank 1
answered on 14 May 2013, 09:56 PM
Resolved this by registering an Observer against a property of the class bound to the form.  I ensured my CommitEdit() updates this attribute by accessing the object via DataForm.CurrentItem.

Regards,

-A.
0
Art Kedzierski
Top achievements
Rank 2
answered on 02 Jul 2013, 12:30 PM
I am facing this same issue and would love to see your code solution. I have not used an Observer before.
0
Daniel B.
Top achievements
Rank 1
answered on 01 Jul 2015, 01:10 AM

I am facing similar too, though against my code-behind where i will then RaiseEvent

 code example would be great please

0
Stefan
Telerik team
answered on 03 Jul 2015, 01:55 PM
Hello,

Since you need to access the view model from code-behind, you can use the DataContext of RadDataForm and set a property per your requirements.
(this.DataForm.DataContext as MyViewModel).MyProperty = //set property value

Can you please confirm if this fits your requirements?

Best Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DataForm
Asked by
Antonio
Top achievements
Rank 1
Answers by
Antonio
Top achievements
Rank 1
Art Kedzierski
Top achievements
Rank 2
Daniel B.
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or