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

Simple Edit Form

5 Answers 240 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 01 Apr 2013, 10:08 PM
I've managed some fairly complicated controls, using RadDataForm, but now I'm trying something very simple, and it's not working.

The issue: I'm trying to create a user control that contains a RadDataForm that edits one object.  There's no readonly, no newitem, no selection of previous or next, there's one single object that should always be displayed in edit mode.

So, I declare a RadDataForm, and bind CurrentItem, but don't bind ItemsSource, and set AutoEdit="True":
<telerik:RadDataForm
    x:Name="radDataForm"
    CurrentItem="{Binding Path=DataContext.recordData,
                    RelativeSource={RelativeSource AncestorType=UserControl},
                    Converter={StaticResource debugBindingConverter}}"
    EditTemplate="{StaticResource editTemplate}"
    ReadOnlyTemplate="{StaticResource readonlyTemplate}"
    AutoEdit="True"
    AutoGenerateFields="False"
    />

The two templates at this point simply contain labels, declaring "EditItemplate" and "ReadonlyTemplate", so I can see which is being loaded. The code-behind is simple:
public partial class MyUserControl : KorUserControl
{
    public MyUserControl()
    {
        InitializeComponent();
        this.DataContext = new MyUserControlVM();
    }
}
 
public class MyUserControlVM
{
    public RecordData recordData
    { get; set; }
 
    public MyUserControlVM()
    {
        this.recordData = new RecordData();
    }
}
 
public class RecordData : INotifyPropertyChanged, IDataErrorInfo, IEditableObject
{
    public string aTestField
    { get; set; }
         
    #region INotifyPropertyChanged Members
    ...
    #endregion
 
    #region IDataErrorInfo Members
    ...
    #endregion
 
    #region IEditableObject Members
    ...
    #endregion
}

My problem? The form loads the readonly template, instead of the edit template.

Why?

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 02 Apr 2013, 07:36 AM
Hi Jeffrey,

I tried to reproduce the behavior you described, but without any success. Could you take a look at the sample attached and let me know whether I am missing anything ? 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Jeff
Top achievements
Rank 1
answered on 02 Apr 2013, 01:59 PM

You’re setting the DataContext in XAML.

 

Try setting the DataContext in MainWindow’s constructor.

 

0
Maya
Telerik team
answered on 02 Apr 2013, 03:33 PM
Hi Jeffrey,

This is a kind of expected behavior since in this case there is a small difference between the time we make all the check for the right behavior and the time the source/item/datacontext are set.
What you should do is to set the CurrentItem right after the data context is set as well:

public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new MyViewModel();
            this.dataForm.CurrentItem = (this.DataContext as MyViewModel).Clubs[0];
        }


All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Andrew
Top achievements
Rank 1
answered on 28 Aug 2017, 04:11 PM

I'm trying to do this same thing where I want the DataForm functionality but for a single object.  I want the lables and validation.  The problem is that when I take the sample code into my application, I don't want all the controls at the top and bottom of the form.  In the sample, the edit controls don't show at the top of the form, but I don't see how this is turned off.  Also, there are OK and Cancel buttons at the bottom that I don't want.

I'm just tying to build a simple edit form for a business entity and maybe this is just too simple for the Telerik complexity but I want this to have all the same behavior as the rest of the Telerik DataForms in the application without having to build this for every TextBox and Label that I add to the form.

Is there a basic DataFormDataField like control that binds to a single property without all the extra controls associated with a DataForm?

0
Stefan
Telerik team
answered on 31 Aug 2017, 11:28 AM
Hi Andrew,

Thank you for the detailed explanation of your requirement.

I will try to shed some light on the sample application demonstrated in this thread. Firstly, the Add, Edit and Delete buttons on the top of the control would not be available when the ItemsSource of the control is not being set. As you can see in the demo, only the CurrentItem of the control is defined. As to the Commit and Cancel buttons, in order to remove them, you need to edit the default template of the control. You may find the templates structure topic also useful on this matter.

In addition to this, you can check out our RadPropertyGrid control as it can also be used for such requirements.

I hope that this helps. Of course, in case further assistance is needed, feel free to approach me.

Best Regards,
Stefan X1
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
DataForm
Asked by
Jeff
Top achievements
Rank 1
Answers by
Maya
Telerik team
Jeff
Top achievements
Rank 1
Andrew
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or