Custom Command Provider executing actions on View Model

5 posts, 0 answers
  1. Antonio
    Antonio avatar
    2 posts
    Member since:
    Apr 2013

    Posted 14 May 2013 Link to this post

    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();

            }
        }
  2. Antonio
    Antonio avatar
    2 posts
    Member since:
    Apr 2013

    Posted 14 May 2013 Link to this post

    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.
  3. DevCraft banner
  4. Art Kedzierski
    Art Kedzierski avatar
    107 posts
    Member since:
    Nov 2009

    Posted 02 Jul 2013 Link to this post

    I am facing this same issue and would love to see your code solution. I have not used an Observer before.
  5. Daniel B.
    Daniel B. avatar
    18 posts
    Member since:
    Apr 2015

    Posted 30 Jun 2015 Link to this post

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

     code example would be great please

  6. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 03 Jul 2015 Link to this post

    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
Back to Top
DevCraft banner