Simple Edit Form

6 posts, 0 answers
  1. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 01 Apr 2013 Link to this post

    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?
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Apr 2013 Link to this post

    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.

  3. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 02 Apr 2013 Link to this post

    You’re setting the DataContext in XAML.

     

    Try setting the DataContext in MainWindow’s constructor.

     

  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Apr 2013 Link to this post

    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.

  5. Andrew
    Andrew avatar
    1 posts
    Member since:
    May 2014

    Posted 28 Aug in reply to Maya Link to this post

    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?

  6. Stefan
    Admin
    Stefan avatar
    774 posts

    Posted 31 Aug Link to this post

    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.
Back to Top