Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Integrated Help system in a WPF Application

, 20 Jun 2013 CPOL
Quick guideline to understand a workflow of screen without reading long and boring(!!) documentation guide.
integratedhelpinwpf-noexe.zip
IntegratedHelpInWPF
IntegratedHelpInWPF
AttachProperties
bin
Debug
DynamicHelpReference
IntegratedHelpInWPF.vshost.exe.manifest
Commands
DynamicHelpReference
IntegratedHelpInWPF.csproj.user
Languages
Popup
Properties
Settings.settings
Resources
integratedhelpinwpf.zip
IntegratedHelpInWPF.exe
IntegratedHelpInWPF.vshost.exe
IntegratedHelpInWPF.vshost.exe.manifest
Release
IntegratedHelpInWPF.csproj.user
obj
Debug
Resources
TempPE
Settings.settings
IntegratedHelpInWPF_Revised_-noexe.zip
IntegratedHelpInWPF.vshost.exe.manifest
Converter
IntegratedHelpInWPF.csproj.user
DetailsHelpView.baml
DynamicHelpView.baml
IntegratedHelpInWPF.g.resources
IntegratedHelpInWPF.Properties.Resources.resources
IntegratedHelpInWPF_MarkupCompile.lref
MainWindow.baml
CommonResource.baml
WishlistView.baml
Settings.settings
IntegratedHelpInWPF.v11.suo
IntegratedHelpInWPF_Revised_.zip
Assembly
System.Windows.Interactivity.dll
IntegratedHelpInWPF.exe
IntegratedHelpInWPF.pdb
IntegratedHelpInWPF.vshost.exe
IntegratedHelpInWPF.vshost.exe.manifest
System.Windows.Interactivity.dll
IntegratedHelpInWPF.csproj.user
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
DetailsHelpView.baml
DynamicHelpView.baml
IntegratedHelpInWPF.csproj.GenerateResource.Cache
IntegratedHelpInWPF.csprojResolveAssemblyReference.cache
IntegratedHelpInWPF.exe
IntegratedHelpInWPF.g.resources
IntegratedHelpInWPF.pdb
IntegratedHelpInWPF.Properties.Resources.resources
IntegratedHelpInWPF_MarkupCompile.cache
IntegratedHelpInWPF_MarkupCompile.i.cache
IntegratedHelpInWPF_MarkupCompile.lref
MainWindow.baml
CommonResource.baml
Properties.Resources.Designer.cs.dll
WishlistView.baml
Settings.settings
IntegratedHelpInWPF.v11.suo
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using IntegratedHelpInWPF.Commands;

namespace IntegratedHelpInWPF
{
    public class MainViewModel : BaseViewModel
    {        
        public MainViewModel()
        {
            this.View = new MainWindow {ViewModel = this};
            _wishlistCommand = new DelegateCommand(ExecuteWishlistCommand);
        }

        private void ExecuteWishlistCommand(object obj)
        {
            var wishViewModel = new WishlistViewModel();
            wishViewModel.ShowDialog();
        }

        private DynamicHelpViewModel _dynamicHelpViewModel;

        public DynamicHelpViewModel DynamicHelpViewModel
        {
            get
            {
                if (_dynamicHelpViewModel == null)
                {
                    _dynamicHelpViewModel = new DynamicHelpViewModel();
                }
                return _dynamicHelpViewModel;
            }
            set { _dynamicHelpViewModel = value; NotifyPropertyChanged(()=> DynamicHelpViewModel); }
        }

        private readonly ICommand _wishlistCommand;
        public ICommand WishlistCommand
        {
            get { return _wishlistCommand; }
        }
    }

    public abstract class BaseViewModel : INotifyPropertyChanged
    {
        private IBaseView _view;
        public IBaseView View
        {
            get { return _view; }
            set { _view = value; NotifyPropertyChanged(()=>View); }
        }
        public virtual bool CleanUpResource()
        {
            return true;
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Notify using pre-made PropertyChangedEventArgs
        /// </summary>
        /// <param name="args"></param>
        protected void NotifyPropertyChanged(PropertyChangedEventArgs args)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, args);
            }
        }

        /// <summary>
        /// Notify using String property name
        /// </summary>
        protected void NotifyPropertyChanged(String propertyName)
        {
            this.VerifyPropertyName(propertyName);
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public static string GetPropertyName(Expression<Func<Object>> propertyExpression)
        {
            var lambda = propertyExpression as LambdaExpression;
            MemberExpression memberExpression;
            if (lambda.Body is UnaryExpression)
            {
                var unaryExpression = lambda.Body as UnaryExpression;
                memberExpression = unaryExpression.Operand as MemberExpression;
            }
            else
            {
                memberExpression = lambda.Body as MemberExpression;
            }
            var constantExpression = memberExpression.Expression as ConstantExpression;
            var propertyInfo = memberExpression.Member as PropertyInfo;

            return propertyInfo.Name;
        }

        protected void NotifyPropertyChanged(Expression<Func<Object>> propertyExpression)
        {
            string propertyName = GetPropertyName(propertyExpression);

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region Debugging Aides

        /// <summary>
        /// Warns the developer if this object does not have
        /// a public property with the specified name. This 
        /// method does not exist in a Release build.
        /// </summary>
        [Conditional("DEBUG")]
        [DebuggerStepThrough]
        public void VerifyPropertyName(string propertyName)
        {
#if !SILVERLIGHT
            // Verify that the property name matches a real,  
            // public, instance property on this object.
            if (TypeDescriptor.GetProperties(this)[propertyName] == null)
            {
                string msg = "Invalid property name: " + propertyName;

                if (this.ThrowOnInvalidPropertyName)
                    throw new Exception(msg);
                else
                    Debug.Fail(msg);
            }
#endif
        }

        /// <summary>
        /// Returns whether an exception is thrown, or if a Debug.Fail() is used
        /// when an invalid property name is passed to the VerifyPropertyName method.
        /// The default value is false, but subclasses used by unit tests might 
        /// override this property's getter to return true.
        /// </summary>
        protected virtual bool ThrowOnInvalidPropertyName { get; private set; }

        #endregion // Debugging Aides
    }

    public interface IMainView : IBaseView
    {
    }

    public interface IBaseView
    {
        BaseViewModel ViewModel { set;  }
    }
}

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 Code Project Open License (CPOL)

Share

About the Author

Morshed Anwar
Team Leader Adaptive Enterprise Limited (www.ael-bd.com)
Bangladesh Bangladesh
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 20 Jun 2013
Article Copyright 2012 by Morshed Anwar
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid