Click here to Skip to main content
15,891,431 members
Articles / Web Development / HTML

WPF x FileExplorer x MVVM

Rate me:
Please Sign up or sign in to vote.
4.99/5 (52 votes)
24 Nov 2012LGPL323 min read 290.1K   9.4K   228  
This article describe how to construct FileExplorer controls included DirectoryTree and FileList, using Model-View-ViewModel (MVVM) pattern.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickZip.MVVM;
using QuickZip.UserControls.MVVM.Model;
using QuickZip.UserControls.MVVM.ViewModel;
using System.Diagnostics;
using System.Collections.ObjectModel;

namespace QuickZip.UserControls.MVVM
{
    public abstract class BaseStatusbarViewModel : ExplorerRootModelBase
    {

        #region Constructor

        public BaseStatusbarViewModel()
        {
            //setupItemList();

            //StatusItemList = new ObservableCollection<MetadataViewModel>(from mm in innerGetMetadataModel() select mm.ToViewModel());
            //StatusItemList = new AsyncObservableCollection<MetadataViewModel>(
            // from mm in innerGetMetadataModel() select mm.ToViewModel()
            // );
            //StatusItemList.Load();
        }

        #endregion

        #region Methods


        public virtual void UpdateStatusbar()
        {
            StatusItemList = new ObservableCollection<MetadataViewModel>(from mm in innerGetMetadataModel() select mm.ToViewModel());
        }        


        private void setupItemList()
        {
            //_statusItemList = new AsyncObservableCollection<MetadataViewModel>();                
        }

        protected virtual IEnumerable<GenericMetadataModel> getMetadataModel()
        {
            yield break;
        }

        protected virtual IEnumerable<GenericMetadataModel> innerGetMetadataModel()
        {
            if (IsSimpleStatusbar)
                yield return new GenericMetadataModel<string>(StatusText, "KEY_SimpleStatus");
            else
                using (IEnumerator<GenericMetadataModel> enumerator = getMetadataModel().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                        yield return enumerator.Current;
                }
                    
        }

        #endregion

        #region Data

        private ObservableCollection<MetadataViewModel> _statusItemList = null;
        private bool _isSimpleStatusbar = false;
        private string _statusText = "";

        #endregion

        #region Public Properties
        public ObservableCollection<MetadataViewModel> StatusItemList
        {
            get { return _statusItemList; }
            protected set { _statusItemList = value; NotifyPropertyChanged("StatusItemList"); }
        }

        public string StatusText
        {
            get { return _statusText; }
            set { _statusText = value; NotifyPropertyChanged("StatusText"); UpdateStatusbar(); }
        }
        
        public bool IsSimpleStatusbar
        {
            get { return _isSimpleStatusbar; }
            set { _isSimpleStatusbar = value; NotifyPropertyChanged("IsSimpleStatusbar"); }
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder
Hong Kong Hong Kong

Comments and Discussions