20 private static Dictionary<GridViewColumn, double> _lastGridViewColumnWidths =
new Dictionary<GridViewColumn, double>();
25 public static readonly DependencyProperty
CollapseableColumnProperty = DependencyProperty.RegisterAttached(
"CollapseableColumn", typeof(
bool), typeof(
GridViewBehaviors),
new UIPropertyMetadata(
false, OnCollapseableColumnChanged));
47 private static void OnCollapseableColumnChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
49 GridViewColumnHeader header = obj as GridViewColumnHeader;
53 header.IsVisibleChanged +=
new DependencyPropertyChangedEventHandler(AdjustWidth);
56 private static void AdjustWidth(
object sender, DependencyPropertyChangedEventArgs e)
58 GridViewColumnHeader header = sender as GridViewColumnHeader;
62 double newWidth =
double.NaN;
64 if (header.Visibility == Visibility.Visible)
66 if (_lastGridViewColumnWidths.ContainsKey(header.Column))
68 newWidth = _lastGridViewColumnWidths[header.Column];
72 newWidth = header.Column.ActualWidth;
73 _lastGridViewColumnWidths.Add(header.Column, newWidth);
75 header.Column.Width = newWidth;
80 if (header.Column.ActualWidth != 0)
82 if (_lastGridViewColumnWidths.ContainsKey(header.Column))
84 _lastGridViewColumnWidths[header.Column] = header.Column.ActualWidth;
88 _lastGridViewColumnWidths.Add(header.Column, header.Column.ActualWidth);
91 header.Column.Width = 0;