Vývoj moderních aplikací na platformě Microsoft .NET

Je vyžadována podpora jazyka JavaScript

Některé stránky na tomto webu vyžadují podporu jazyka JavaScript. Váš webový prohlížeč jazyk JavaScript nepodporuje nebo jazyk JavaScript není povolen.

Chcete-li zjistit, zda webový prohlížeč podporuje jazyk JavaScript nebo jazyk JavaScript chcete povolit, přečtěte si nápovědu k vašemu webovému prohlížeči.


datagridcolumnbindinghelper.cs

Download file

Toto je zdrojový kód souboru datagridcolumnbindinghelper.cs

using System;
using System.Windows;
using System.Windows.Controls;

namespace SilverlightApplication
{
    /// <summary>
    /// Helper class to set DataGridColumn properties via binding.
    /// </summary>
    public class DataGridColumnBindingHelper
    {
        /// <summary>
        /// Header DependencyProperty
        /// </summary>
        public static readonly DependencyProperty HeaderProperty = DependencyProperty.RegisterAttached("Header", typeof(object), typeof(DataGridColumnBindingHelper), new PropertyMetadata(null, OnHeaderPropertyChanged));

        /// <summary>
        /// Header Property getter
        /// </summary>
        public static object GetHeader(DependencyObject source)
        {
            return (object)source.GetValue(DataGridColumnBindingHelper.HeaderProperty);
        }

        /// <summary>
        /// Header Property setter
        /// </summary>
        public static void SetHeader(DependencyObject target, object value)
        {
            target.SetValue(DataGridColumnBindingHelper.HeaderProperty, value);
        }

        private static void OnHeaderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var column = d as DataGridColumn;
            if (column == null)
            {
                return;
            }

            column.Header = e.NewValue;
        }

        /// <summary>
        /// Visibility DependencyProperty
        /// </summary>
        public static readonly DependencyProperty VisibilityProperty = DependencyProperty.RegisterAttached("Visibility", typeof(Visibility), typeof(DataGridColumnBindingHelper), new PropertyMetadata(Visibility.Visible, OnVisibilityPropertyChanged));

        /// <summary>
        /// Visibility Property getter
        /// </summary>
        public static Visibility GetVisibility(DependencyObject source)
        {
            return (Visibility)source.GetValue(DataGridColumnBindingHelper.VisibilityProperty);
        }

        /// <summary>
        /// Visibility Property setter
        /// </summary>
        public static void SetVisibility(DependencyObject target, Visibility value)
        {
            target.SetValue(DataGridColumnBindingHelper.VisibilityProperty, value);
        }

        private static void OnVisibilityPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var column = d as DataGridColumn;
            if (column == null)
            {
                return;
            }

            column.Visibility = (Visibility)e.NewValue;
        }

        /// <summary>
        /// IsReadOnly DependencyProperty
        /// </summary>
        public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.RegisterAttached("IsReadOnly", typeof(bool), typeof(DataGridColumnBindingHelper), new PropertyMetadata(false, OnIsReadOnlyPropertyChanged));

        /// <summary>
        /// IsReadOnly Property getter
        /// </summary>
        public static bool GetIsReadOnly(DependencyObject source)
        {
            return (bool)source.GetValue(DataGridColumnBindingHelper.IsReadOnlyProperty);
        }

        /// <summary>
        /// IsReadOnly Property setter
        /// </summary>
        public static void SetIsReadOnly(DependencyObject target, Visibility value)
        {
            target.SetValue(DataGridColumnBindingHelper.IsReadOnlyProperty, value);
        }

        private static void OnIsReadOnlyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var column = d as DataGridColumn;
            if (column == null)
            {
                return;
            }

            column.IsReadOnly = Convert.ToBoolean(e.NewValue);
        }
    }
}