Simple Edit Form

4 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. UI for WPF is Visual Studio 2017 Ready
  4. 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.

     

  5. 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.

Back to Top