Click here to Skip to main content
15,886,830 members
Articles / Programming Languages / C# 4.0

Silverlight Multi-Binding

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
17 Nov 2011CPOL4 min read 30.4K   435   11  
Performing multi-binding in Silverlight.
using System;
using System.Globalization;
using System.Windows.Data;

namespace slMultiBinding
{
    public class Bindings2ConcatString : IMultiValueConverter// IMyMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string ret = "";
            foreach (Object param in values)
            {
                if (param != null)
                {
                    ret += param.ToString();
                }
            }
            return ret;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }



    public class Num2Pow : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Math.Pow(System.Convert.ToDouble(value), System.Convert.ToDouble(parameter));
        }

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

    public class Nums2Sum : IMultiValueConverter
    {

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            //return 0;
            //if (values == null || (values.AsQueryable().Any(v => v == null || v == DependencyProperty.UnsetValue)))
            //{
            //    return 0;
            //}

            double ret = 0;
            foreach (Object param in values)
            {
                if (param != null)
                {
                    ret += System.Convert.ToDouble(param);
                }
            }
            return ret;
        }

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

}

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)


Written By
Software Developer (Senior) self employed
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions