Click here to Skip to main content
15,896,500 members
Articles / Desktop Programming / WPF

A (Mostly) Declarative Framework for Building Simple WPF-based Wizards

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
7 Mar 2011LGPL322 min read 19.3K   229   15  
A declarative framework for building WPF wizards.
/*
* Olbert.Utils.WPF
* Converters and Validators for use in WPF applications
* Copyright (C) 2011  Mark A. Olbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published 
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Olbert.Utilities.WPF
{
    /// <summary>
    /// Does a logical OR on all the values given to it for conversion, which should be booleans 
    /// (if a value isn't a boolean, it's treated as a false by default)
    /// </summary>
    public class AnyTrueConverter : IMultiValueConverter
    {
        /// <summary>
        /// Returns true if at least one of the values being checked is a boolean true. Non-boolean values
        /// are interpreted as false.
        /// </summary>
        /// <param name="values">the values to be converted</param>
        /// <param name="targetType">ignored</param>
        /// <param name="parameter">ignored</param>
        /// <param name="culture">ignored</param>
        /// <returns>true if at least one of the supplied values is true, false otherwise</returns>
        public object Convert( object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
            bool curBool = false;

            foreach( object curVal in values )
            {
                if( curVal is bool ) curBool = (bool) curVal;
                else curBool = false;

                if( curBool ) return true;
            }

            return false;
        }

        /// <summary>
        /// Not implemented, because there's no way to know what kind of objects the supplied value was
        /// originally derived from. Throws a NotImplementedException.
        /// </summary>
        /// <param name="value">ignored</param>
        /// <param name="targetTypes">ignored</param>
        /// <param name="parameter">ignored</param>
        /// <param name="culture">ignored</param>
        /// <returns>not applicable</returns>
        public object[] ConvertBack( object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture )
        {
            throw new NotImplementedException();
        }
    }
}

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
Jump for Joy Software
United States United States
Some people like to do crossword puzzles to hone their problem-solving skills. Me, I like to write software for the same reason.

A few years back I passed my 50th anniversary of programming. I believe that means it's officially more than a hobby or pastime. In fact, it may qualify as an addiction Smile | :) .

I mostly work in C# and Windows. But I also play around with Linux (mostly Debian on Raspberry Pis) and Python.

Comments and Discussions