Click here to Skip to main content
15,885,653 members
Articles / Desktop Programming / WPF

Displaying a Data Matrix in WPF

Rate me:
Please Sign up or sign in to vote.
4.94/5 (68 votes)
14 Jun 2009CPOL9 min read 270.1K   3.8K   157  
Reviews a matrix control that can be data bound and visually styled with ease
using System;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;

namespace MatrixLib.Layout
{
    /// <summary>
    /// The value converter applied to bindings against properties of 
    /// MatrixGridChildMonitor that informs a MatrixGrid of the Grid.Row
    /// and Grid.Column settings applied to its child elements.
    /// </summary>
    class MatrixGridChildConverter : IValueConverter
    {
        #region Constructor

        public MatrixGridChildConverter(MatrixGrid matrixGrid)
        {
            _matrixGrid = matrixGrid;
        }

        #endregion // Constructor

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int)
            {
                int index = (int)value;

                if (parameter == Grid.RowProperty)
                    _matrixGrid.InspectRowIndex(index);
                else
                    _matrixGrid.InspectColumnIndex(index);
            }

            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion // IValueConverter Members

        #region Fields

        readonly MatrixGrid _matrixGrid;

        #endregion // Fields
    }
}

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)
United States United States
Josh creates software, for iOS and Windows.

He works at Black Pixel as a Senior Developer.

Read his iOS Programming for .NET Developers[^] book to learn how to write iPhone and iPad apps by leveraging your existing .NET skills.

Use his Master WPF[^] app on your iPhone to sharpen your WPF skills on the go.

Check out his Advanced MVVM[^] book.

Visit his WPF blog[^] or stop by his iOS blog[^].

See his website Josh Smith Digital[^].

Comments and Discussions