Click here to Skip to main content
Click here to Skip to main content

MVVM # Episode 1

By , 7 Feb 2013
 
MVVMSharp_Code.zip
CustomerMaintenance
Controllers
Base Classes
bin
Release
Controllers.csproj.vs10x
Properties
CustomerMaintenance
bin
Debug
CustomerMaintenance.vshost.exe
CustomerMaintenance.vshost.exe.manifest
Release
CustomerMaintenance.csproj.user
CustomerMaintenance.csproj.vs10x
Properties
Settings.settings
Messengers
bin
Release
Messengers.csproj.vs10x
Properties
Model
bin
Debug
Release
Models.csproj.vs10x
Properties
Service
bin
Release
Properties
Services.csproj.vs10x
ViewModel
BaseClasses
bin
Release
Properties
ViewData
ViewModels.csproj.vs10x
Views
Base Classes
bin
Release
Converters
DesignTimeData
Properties
Settings.settings
Views.csproj.vs10x
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Views
{
    /*
     * This source file contains all the converters used.
     */


    /// <summary>
    /// Returns false if the object is null, true otherwise.
    /// handy for using when something needs to be enabled or disabled depending on
    /// whether a value has been selected from a list.
    /// </summary>
    [ValueConversion(typeof(object), typeof(bool))]
    public class NullToFalseBooleanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (value != null);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }

    /// <summary>
    /// Returns false if the object is null, true otherwise.
    /// handy for using when something needs to be enabled or disabled depending on
    /// whether a value has been selected from a list.
    /// </summary>
    [ValueConversion(typeof(object), typeof(Visibility))]
    public class NullToHiddenVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return Visibility.Hidden;
            }
            else
            {
                return Visibility.Visible;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of use 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)

About the Author

_Maxxx_
Software Developer (Senior)
Australia Australia
Software developer par excellence,sometime artist, teacher, musician, husband, father and half-life 2 player (in no particular order either of preference or ability)

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 7 Feb 2013
Article Copyright 2011 by _Maxxx_
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid