Data from RadDataForm doesn't fall into property of object to which RadDataForm is bound.

4 posts, 1 answers
  1. Eugene
    Eugene avatar
    83 posts
    Member since:
    Jan 2016

    Posted 20 Apr Link to this post

    Hi! I try to use RadDataForm in my WPF MVVM Prism 6 application. Since I began to use this control I've collided with some problems - data from form is not passed into properies of the object to which RadDataForm is bound. Below is the class to object of which RadDataForm is bound:

    public class Group : IEditableObject
    {
       struct GroupData
       {
          internal string name;
       }
     
       private GroupData _newGroupData;
       private GroupData _backupGroupData;
       private bool _isEditMode = false;
     
       public Group()
       {
          this._newGroupData = new GroupData();
          this._newGroupData.name = string.Empty;
       }
       public string Name
       {
          get { return this._newGroupData.name; }
          set { this._newGroupData.name = value; }
       }
     
       public void BeginEdit()
       {
          if(!this._isEditMode)
          {
             this._backupGroupData = this._newGroupData;
             this._isEditMode = true;
          }
       }
     
       public void CancelEdit()
       {
          if (this._isEditMode)
          {
             this._newGroupData = this._backupGroupData;
             this._isEditMode = false;
          }
       }
     
       public void EndEdit()
       {
          if (this._isEditMode)
          {
             this._backupGroupData = new GroupData();
             this._isEditMode = false;
          }
       }
     
       public override string ToString()
       {
          StringWriter stringWriter = new StringWriter();
          stringWriter.Write(this.Name);
          return stringWriter.ToString();
       }
    }

    Then in view model:

    private Group _profileElementsGroup;
    public Group ProfileElementsGroup
    {
        get { return this._profileElementsGroup; }
        set { this.SetProperty(ref this._profileElementsGroup, value); }
    }

    Then in XAML of view:
    <Grid.Resources>
      <DataTemplate x:Key="GroupTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <telerik:DataFormDataField Grid.Row="0" Label="GroupName" DataMemberBinding="{Binding ProfileElementsGroup.Name, Mode=TwoWay}"/>
        </Grid>
      </DataTemplate>
    </Grid.Resources>
     
    <telerik:RadDataForm HorizontalAlignment="Center" VerticalAlignment="Top"
                                 AutoGenerateFields="False" Header="Add Element Group of Profile of Device" ReadOnlyTemplate="{StaticResource GroupTemplate}"
                                 EditTemplate="{StaticResource GroupTemplate}" CurrentItem="{Binding ProfileElementsGroup}">
                <telerik:EventToCommandBehavior.EventBindings>
                    <telerik:EventBinding
                        Command="{Binding HandleEndEditNewProfileElementsGroupCommand}"
                        EventName="EditEnded"
                        PassEventArgsToCommand="True"/>
                </telerik:EventToCommandBehavior.EventBindings>
    </telerik:RadDataForm>

     

    When I printing in my RadDataForm in Name field I set breakpoint in C# code of Name property and this breakpoint is not activated. So data from RadDataForm doesn't fall into ProfileElementsGroup.Name property. What I do wrong? Please help.

  2. Eugene
    Eugene avatar
    83 posts
    Member since:
    Jan 2016

    Posted 21 Apr in reply to Eugene Link to this post

    Here I add a little. 1) I initialize ProfileElementsGroup property in view model constructor:

    public DeviceProfileViewModel()
    {
       this.ProfileElementsGroup = new Group();
       . . . . .
    }

    As I wrote and showed above - the RadDataForm is bound to this property in XAML.

    2) In "Binding HandleEndEditNewProfileElementsGroupCommand"  command I take the value of ProfileElementsGroup.Name property and use it as required by the program algorithm.

    3) When I want to check if data from "RadDataForm.Name" DataFormDataField fall into ProfileElementsGroup.Name property then I set debuging breakpoint in definition of this property in "Group" class code. Then I set focus in "GroupName" DataFormField in RadDataForm and begin to print there, but the breakpoint is not activated during printing.

    So I ask you again please help me solve the problem.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Apr Link to this post

    Hi Eugene,

    DataContext of the data form in this case would be the ProfileElementGroup item that you bind to the CurrentItem property of the control. So, you can bind directly to its Name property in the definition of the DataFormDataFiled. 
    Could you try the following and let me know whether it meets your requirements: 
    <telerik:DataFormDataField Grid.Row="0" Label="GroupName" DataMemberBinding="{Binding Name, Mode=TwoWay}"/>


    Regards,
    Maya
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  5. Eugene
    Eugene avatar
    83 posts
    Member since:
    Jan 2016

    Posted 25 Apr in reply to Maya Link to this post

    Thank you very much, Maya. You've helped me very.
Back to Top