|
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Markup;
namespace SilverlightMarkupExtensions
{
public class MinNumberOfSetConverter : MarkupExtension, IMultiValueConverter
{
public MinNumberOfSetConverter()
{
}
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
int minNumberOfSet;
if( !int.TryParse(parameter as String, out minNumberOfSet) ) minNumberOfSet = values.Length;
int numberOfSet = 0;
for (int i = 0; i < values.Length; i++)
{
bool? boolValue = values[i] as bool?;
if (boolValue.GetValueOrDefault()) numberOfSet++;
if (numberOfSet >= minNumberOfSet) return true;
}
return numberOfSet >= minNumberOfSet;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
public override Object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}
|
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.
Henrik Jonsson is a Microsoft Professional Certified Windows Developer (MCPD) that currently works as an IT consultant in Västerås, Sweden.
Henrik has worked in several small and large software development projects in various roles such as architect, developer, CM and tester.
He regularly reads The Code Project articles to keep updated about .NET development and get new ideas. He has contributed with articles presenting some useful libraries for
Undo/Redo,
Dynamic Linq Sorting and a
Silverlight 5 MultiBinding solution.