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

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

3 Answers 135 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Eugene
Top achievements
Rank 1
Eugene asked on 20 Apr 2016, 02:01 PM

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.

3 Answers, 1 is accepted

Sort by
0
Eugene
Top achievements
Rank 1
answered on 21 Apr 2016, 05:57 AM

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.

0
Accepted
Maya
Telerik team
answered on 25 Apr 2016, 07:03 AM
Hi Eugene,

DataContext of the data 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.
0
Eugene
Top achievements
Rank 1
answered on 25 Apr 2016, 12:53 PM
Thank you very much, Maya. You've helped me very.
Tags
DataForm
Asked by
Eugene
Top achievements
Rank 1
Answers by
Eugene
Top achievements
Rank 1
Maya
Telerik team
Share this question
or