Project Description

MVVM Framework is a set of base implementation of MVVM principles and components helping to quick and efficient develop WPF business applications.

The MVVM Framework makes it easier to develop WPF applications using the Model-View-ViewModel design pattern. It covers three different layers.

Features

  • Different view models
  • Amazing implementation of INotifyPropertyChanged
  • Basic view layer
  • Binding converters
  • And other useful classes, approaches and MVVM features

View

The MVVMFramework.View library contains a base implementation of Window. This realization contains basic communication with view model, such as closing Window by view model request.
Also this library contains value converters you can use to data-binding operations.

Controls

Expander
expander.png
Watermark
watermark.png
DateTimePicker
datetimepicker.png

Converters

BoolToVisibilityConverter
<view:BoolToVisibilityConverter x:Key="VisibleIfTrue"/>
<view:BoolToVisibilityConverter x:Key="CollapsedIfTrue" IsReversed="True"/>
<view:BoolToVisibilityConverter x:Key="HiddenIfFalse" UseHidden="True"/>
<view:BoolToVisibilityConverter x:Key="HiddenIfTrue" UseHidden="True" IsReversed="True"/>

IntegerToVisibilityConverter
<view:IntegerToVisibilityConverter x:Key="VisibleIfZero" IntegerValue="0"/>
<view:IntegerToVisibilityConverter x:Key="CollapsedIfZero" IntegerValue="0" IsReversed="True"/>
<view:IntegerToVisibilityConverter x:Key="VisibleIfSeven" IntegerValue="7" FallbackBehavior="ThrowException"/>

DefaultValueToVisibilityConverter
<view:DefaultValueToVisibilityConverter x:Key="VisibleIfDefault"/>
<view:DefaultValueToVisibilityConverter x:Key="CollapsedIfDefault" IsReversed="True"/>

View Models

The MVVMFramework.ViewModel library contains a base implementations of view models for use it in a different situations:
  • Browse view. Browse is one of the primary views that contains a list of items usually presented as DataGrid or ListView. In this case you can use BrowseEntityViewModel. It helps you to quick build datacontext for this sort of view.
    class UsersVM : BrowseEntitiesViewModel<User>
    {
        protected override string GetTitle()
        {
            return "Users";
        }

        protected override IEnumerable<User> LoadEntities()
        {
            return AppModel.Instance.GetUsers();
        }

        protected override bool RunRequest(User entity, Requests request, out User result)
        {
            if (request == Requests.Insert)
                entity = new User();

            UserVM vm = new UserVM(entity, request);
            UserView view = new UserView(vm);
            if (view.ShowDialog() == true)
            {
                result = entity;
                return true;
            }

            result = null;
            return false;
        }        
    }
  • Edit view. It is a form for editing object. Contains a set of controls to edit fields of object. You need to use EditEntityViewModel for this sort of view.
    class UserVM : EditEntityViewModelBase<User>
    {
        protected override bool Save(User entity)
        {
            try
            {
                AppModel.Instance.SaveUser(entity);
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(GetExceptionMessage(ex), "Unable to save user");
            }
            return false;
        }

        protected override bool Validate(User entity, out string validationMessage)
        {
            if (string.IsNullOrEmpty(entity.UserName))
            {
                validationMessage = "User Name must be specified";
                return false;
            }

            validationMessage = null;
            return true;
        }

        protected override string GetTitle()
        {
            if (Request == Requests.View)
                return string.Format("{0}", Entity.UserName);

            if (Request == Requests.Change)
                return "User will be changed";

            if (Request == Requests.Insert)
                return "User will be added";

            return "User";
        }
    }

See documentation for more information

Last edited May 12, 2013 at 3:04 PM by dmitry_dk, version 40