DataGridHeadersVisibilityToVisibilityConverter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Controls / DataGridHeadersVisibilityToVisibilityConverter.cs / 1305600 / DataGridHeadersVisibilityToVisibilityConverter.cs

                            //---------------------------------------------------------------------------- 
//
// Copyright (C) Microsoft Corporation.  All rights reserved.
//
//--------------------------------------------------------------------------- 

using System; 
using System.Globalization; 
using System.Windows;
using System.Windows.Data; 

namespace System.Windows.Controls
{
    ///  
    ///     Converts DataGridHeadersVisibility to Visibility based on the given parameter.
    ///  
    [Localizability(LocalizationCategory.NeverLocalize)] 
    internal sealed class DataGridHeadersVisibilityToVisibilityConverter : IValueConverter
    { 
        /// 
        ///     Convert DataGridHeadersVisibility to Visibility
        /// 
        /// DataGridHeadersVisibility 
        /// Visibility
        /// DataGridHeadersVisibility that represents the minimum DataGridHeadersVisibility that is needed for a Visibility of Visible 
        /// null 
        /// Visible or Collapsed based on the value & converter mode
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        {
            var visible = false;

            if (value is DataGridHeadersVisibility && parameter is DataGridHeadersVisibility) 
            {
                var valueAsDataGridHeadersVisibility = (DataGridHeadersVisibility)value; 
                var parameterAsDataGridHeadersVisibility = (DataGridHeadersVisibility)parameter; 

                switch (valueAsDataGridHeadersVisibility) 
                {
                    case DataGridHeadersVisibility.All:
                        visible = true;
                        break; 
                    case DataGridHeadersVisibility.Column:
                        visible = parameterAsDataGridHeadersVisibility == DataGridHeadersVisibility.Column || 
                                    parameterAsDataGridHeadersVisibility == DataGridHeadersVisibility.None; 
                        break;
                    case DataGridHeadersVisibility.Row: 
                        visible = parameterAsDataGridHeadersVisibility == DataGridHeadersVisibility.Row ||
                                    parameterAsDataGridHeadersVisibility == DataGridHeadersVisibility.None;
                        break;
                } 
            }
 
            if (targetType == typeof(Visibility)) 
            {
                return visible ? Visibility.Visible : Visibility.Collapsed; 
            }
            else
            {
                return DependencyProperty.UnsetValue; 
            }
        } 
 
        /// 
        ///     Not implemented 
        /// 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
           throw new NotImplementedException(); 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------------------- 
//
// Copyright (C) Microsoft Corporation.  All rights reserved.
//
//--------------------------------------------------------------------------- 

using System; 
using System.Globalization; 
using System.Windows;
using System.Windows.Data; 

namespace System.Windows.Controls
{
    ///  
    ///     Converts DataGridHeadersVisibility to Visibility based on the given parameter.
    ///  
    [Localizability(LocalizationCategory.NeverLocalize)] 
    internal sealed class DataGridHeadersVisibilityToVisibilityConverter : IValueConverter
    { 
        /// 
        ///     Convert DataGridHeadersVisibility to Visibility
        /// 
        /// DataGridHeadersVisibility 
        /// Visibility
        /// DataGridHeadersVisibility that represents the minimum DataGridHeadersVisibility that is needed for a Visibility of Visible 
        /// null 
        /// Visible or Collapsed based on the value & converter mode
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        {
            var visible = false;

            if (value is DataGridHeadersVisibility && parameter is DataGridHeadersVisibility) 
            {
                var valueAsDataGridHeadersVisibility = (DataGridHeadersVisibility)value; 
                var parameterAsDataGridHeadersVisibility = (DataGridHeadersVisibility)parameter; 

                switch (valueAsDataGridHeadersVisibility) 
                {
                    case DataGridHeadersVisibility.All:
                        visible = true;
                        break; 
                    case DataGridHeadersVisibility.Column:
                        visible = parameterAsDataGridHeadersVisibility == DataGridHeadersVisibility.Column || 
                                    parameterAsDataGridHeadersVisibility == DataGridHeadersVisibility.None; 
                        break;
                    case DataGridHeadersVisibility.Row: 
                        visible = parameterAsDataGridHeadersVisibility == DataGridHeadersVisibility.Row ||
                                    parameterAsDataGridHeadersVisibility == DataGridHeadersVisibility.None;
                        break;
                } 
            }
 
            if (targetType == typeof(Visibility)) 
            {
                return visible ? Visibility.Visible : Visibility.Collapsed; 
            }
            else
            {
                return DependencyProperty.UnsetValue; 
            }
        } 
 
        /// 
        ///     Not implemented 
        /// 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
           throw new NotImplementedException(); 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK