How to enter in Edit mode when using Object binding in MVVM

2 posts, 0 answers
  1. DenisCL
    DenisCL avatar
    69 posts
    Member since:
    Dec 2009

    Posted 18 Aug 2010 Link to this post

    Hello,
    I bound the RadTreeView to an ObservableCollection of TreeFolderHierarchyItem (my object)
    public class TreeFolderHierarchyItem : INotifyPropertyChanged
        {
            #region properties
            private string _header;
            private bool _isexpanded;
            private string _defaultimagesrc;
            private string _expandedimagesrc;
            private string _collapsedimagesrc;
            private TreeFolderItem _tag;
            private TreeFolderHierarchy _items;
            public string Header
            {
                get { return _header; }
                set
                {
                    if (value != _header)
                    {
                        _header = value;
                        OnPropertyChange("Header");

                    }
                }
            }
            public bool IsExpanded
            {
                get { return _isexpanded; }
                set {
                    if (value != _isexpanded)
                    {
                        _isexpanded = value;
                        OnPropertyChange("IsExpanded");
                    }
                }
            }
            public string DefaultImageSource
            {
                get { return _defaultimagesrc; }
                set
                {
                    if (value != _defaultimagesrc)
                    {
                        _defaultimagesrc = value;
                        OnPropertyChange("DefaultImageSource");
                    }
                }
            }
            public string ExpandedImageSource
            {
                get { return _expandedimagesrc; }
                set
                {
                    if (value != _expandedimagesrc)
                    {
                        _expandedimagesrc = value;
                        OnPropertyChange("ExpandedImageSource");
                    }
                }
            }

            public string CollapsedImageSource
            {
                get { return _collapsedimagesrc; }
                set
                {
                    if (value!= _collapsedimagesrc)
                    {
                        _collapsedimagesrc = value;
                        OnPropertyChange("CollapsedImageSource");
                    }
                }
            }
            public TreeFolderItem Tag
            {
                get { return _tag; }
                set
                {
                    if (value != _tag)
                    {
                        _tag = value;
                        OnPropertyChange("Tag");
                    }
                }
            }
            public TreeFolderHierarchy Items
            {
                get
                {
                    return _items;
                }
                set
                {
                    if (value != _items)
                    {
                        _items = value;
                        OnPropertyChange("Child");
                    }
                }
            }
            public int ID
            {
                get { return Tag.ID; }
                set {
                    if (value != Tag.ID)
                    {
                        Tag.ID = value;
                        OnPropertyChange("ID");
                    }            
                }
            }
     
            public TreeFolderHierarchyItem(TreeFolderItem tag, bool isexpanded )
            {
                _items = new TreeFolderHierarchy();
                if (tag == null)
                    throw new ArgumentException();
                _tag = tag;

                SetProperties(isexpanded);

            }
            private void SetProperties(bool isexpanded)
            {
                _header = _tag.Titre;
                _isexpanded = isexpanded;            
                switch (_tag.Type)
                {
                    case TreeFolderType.Acte:
                        _defaultimagesrc = "folder.png";
                        _expandedimagesrc = "openedfolder.png";
                        _collapsedimagesrc = "folder.png";
                        break;
                    case TreeFolderType.Message:
                        _defaultimagesrc = "sent.png";
                        _expandedimagesrc = "sent.png";
                        _collapsedimagesrc = "sent.png";
                        break;
                    case TreeFolderType.Pdf:
                        _defaultimagesrc = "3Drafts.png";
                        _expandedimagesrc = "3Drafts.png";
                        _collapsedimagesrc = "3Drafts.png";
                        break;
                    case TreeFolderType.Libre:
                        _defaultimagesrc = "1PersonalFolder.png";
                        _expandedimagesrc = "1PersonalFolder.png";
                        _collapsedimagesrc = "1PersonalFolder.png";
                        break;
                }
     

            }

      
            #endregion

            public event PropertyChangedEventHandler PropertyChanged;


            // Helper Methods
            private void OnPropertyChange(string propertyName)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));
                }
            }
        }

    Since this this an observablecollection, I just need to add a new TreeFolderHierarchyItem object to my observable collection
    Adding new Item works fine and RadTreeView control refreshs correctly with the new item. But I want, enter in edit mode for this new item in order to change its header .
    using MyRadViewTree.ItemContainerGenerator.ContainerFromIndex(0) returns always null even when all the node are expanded . So I am not able to iterate into the hierarchy ...
    I thought to set IsEditMode=True but when I calls MyRadTreeVieew.Items I get my Observable collection of TreeFolderHierarchyItem  as expected but useless for setting the EditMode ..
    What am I doing wrong ?
    Thanks for your help

  2. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 20 Aug 2010 Link to this post

    Hello DenisCL,

    You can add IsInEditMode to your TreeFolderHierarchyItem class and use ContainerBinding to bind to the RadTreeViewItem's property. So when you create new TreeFolderHierarchyItem - just set it's IsInEditMode property to true.
    One more option is to handle the ItemPrepared event (it is fired each time new item is added (prepared) and set it's IsInEditMode proeprty to true.
    Let me know if this is working for you.
    Thank you.

    Kind regards,
    Miro Miroslavov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top