﻿

***************************** STEPS TO FOLLOW DURING CREATION OF 'UserControl' *******************************

STEP 1:
Any UserControl that we create in this project solution should be of type 'IVMAUserControl'. So, we have to Implement all properties of IVMAUserControl.

STEP 2:
Copy and paste below Code and do necessary changes wherever we have marked ---->(%000%)


START CODE:


    #region Page Initializer

		--------------->(%000%) /* Change Name to Corresponding 'Page' or 'UserControl' */
        public CONSTRUCTOR() 
        {
            this.InitializeComponent();			
            this.DataContextChanged += ConversationDetailedPage_DataContextChanged;
            InitilizeLocalComponent();           
        }

        private void ConversationDetailedPage_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            this.OnDataContextChanged(args.NewValue);
        }

        #endregion

        #region IVMAPage
        public void InitilizeLocalComponent()
        {
				--------------->(%000%) /* Change Name to Corresponding 'ViewModel' */
			  this.DataContext = App.GetDataContextVM(Global.Common.Enums.VMType.ConversationDetailedVM) as ViewModel.Conversation.ConversationDetailViewModel;
        }
        
        public void OnDataContextChanged(object datacontext) 
        {
            /* NOTE: 
               1. You could assign any ViewModel of type IViewModel any number of times 
               2. you are allowed to change datacontext on runtime based on requirement!!
               */

            if (null != datacontext && this.ViewModelDataContext != datacontext)
            {
                this.ViewModelDataContext = datacontext;
            }
        }

        private Global.Common.Enums.VMType _VMType;
        public Global.Common.Enums.VMType VMType
        {
            get
            {
                return _VMType;
            }
            private set
            {
                _VMType = value;
            }
        }

        public object ViewModelDataContext
        {
           get
            {
				--------------->(%000%) /* Change VMType to Corresponding 'ViewModel' */

                if (VMType == Global.Common.Enums.VMType.ConversationDetailedVM)
                {
                    return this.ConversationVMObj;
                }                
                else
                {
                    return null;
                }
            }
            set
            {
                if (!(value is IViewModel)) throw new InvalidCastException("Value that you are trying to set is not of required 'Type'.");

                /* NOTE: 
                1. You could assign any ViewModel of type IViewModel any number of times 
                2. you are allowed to change datacontext on runtime based on requirement!!
                */

				--------------->(%000%) /* Change VMType to Corresponding 'ViewModel' */
                if (value is ViewModel.Conversation.ConversationDetailViewModel)
                {
                    this.VMType = Global.Common.Enums.VMType.ConversationDetailedVM;

                    this.ConversationVMObj = value as ViewModel.Conversation.ConversationDetailViewModel;

                    this.ConversationVMObj.PropertyChanged -= ConversationVMObj_PropertyChanged;
                    this.ConversationVMObj.PropertyChanged += ConversationVMObj_PropertyChanged;

                    this.listBoxMessages.ItemsSource = this.ConversationVMObj.MessageObservableList;
                }
                else
                {
                    throw new InvalidCastException("Value that you are trying to set is not of required 'Type'.");
                }
            }
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        #endregion 
        #endregion
		

END CODE

***************************** CONGRADULATIONS YOU HAVE CREATED 'IVMAUserControl' *******************************