Social Icons

Tuesday, April 3, 2012

How to create own Grid property binder class in silver light

    
public static class GridPropertyBinder
{
  #region Visibility
  public static readonly DependencyProperty VisibilityBindingProperty = 
            DependencyProperty.RegisterAttached(
                                                "VisibilityBinding",
                                                typeof(object),
                                                typeof(GridPropertyBinder),
                                                new PropertyMetadata(null,
GridPropertyBinder.VisibilityBinding_PropertyChanged));

  public static object GetVisibilityBinding(DependencyObject source)
  {
     return (object)source.GetValue(GridPropertyBinder.VisibilityBindingProperty);
  }
  public static void SetVisibilityBinding(DependencyObject target, 
                                          object value)
  {
     target.SetValue(GridPropertyBinder.VisibilityBindingProperty, value);
  }
  private static void VisibilityBinding_PropertyChanged(DependencyObject d, 
                                                        DependencyPropertyChangedEventArgs e)
  {
     DataGridColumn column = d as DataGridColumn;
     if (column == null) { return; }
     if ((bool)e.NewValue)
     {
       column.Visibility = Visibility.Visible;
     }
     else
     {
        column.Visibility = Visibility.Collapsed;
     }
  }
  #endregion
}

No comments:

Post a Comment

 

Sample text

Sample Text