Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
GridViewBehaviors.cs
1using Microsoft.Xaml.Behaviors;
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
9
11{
18 public class GridViewBehaviors
19 {
20 private static Dictionary<GridViewColumn, double> _lastGridViewColumnWidths = new Dictionary<GridViewColumn, double>();
21
25 public static readonly DependencyProperty CollapseableColumnProperty = DependencyProperty.RegisterAttached("CollapseableColumn", typeof(bool), typeof(GridViewBehaviors), new UIPropertyMetadata(false, OnCollapseableColumnChanged));
26
32 public static bool GetCollapseableColumn(DependencyObject obj)
33 {
34 return (bool)obj.GetValue(CollapseableColumnProperty);
35 }
36
42 public static void SetCollapseableColumn(DependencyObject obj, bool value)
43 {
44 obj.SetValue(CollapseableColumnProperty, value);
45 }
46
47 private static void OnCollapseableColumnChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
48 {
49 GridViewColumnHeader header = obj as GridViewColumnHeader;
50 if (header == null)
51 return;
52
53 header.IsVisibleChanged += new DependencyPropertyChangedEventHandler(AdjustWidth);
54 }
55
56 private static void AdjustWidth(object sender, DependencyPropertyChangedEventArgs e)
57 {
58 GridViewColumnHeader header = sender as GridViewColumnHeader;
59 if (header == null)
60 return;
61
62 double newWidth = double.NaN; // NaN = "Auto"
63
64 if (header.Visibility == Visibility.Visible)
65 {
66 if (_lastGridViewColumnWidths.ContainsKey(header.Column))
67 {
68 newWidth = _lastGridViewColumnWidths[header.Column];
69 }
70 else
71 {
72 newWidth = header.Column.ActualWidth;
73 _lastGridViewColumnWidths.Add(header.Column, newWidth);
74 }
75 header.Column.Width = newWidth;
76 }
77 else
78 {
79 // Save the current width of the column
80 if (header.Column.ActualWidth != 0)
81 {
82 if (_lastGridViewColumnWidths.ContainsKey(header.Column))
83 {
84 _lastGridViewColumnWidths[header.Column] = header.Column.ActualWidth;
85 }
86 else
87 {
88 _lastGridViewColumnWidths.Add(header.Column, header.Column.ActualWidth);
89 }
90 }
91 header.Column.Width = 0;
92 }
93 }
94 }
95}
Behaviour to collapse the GridViewColumn when the Header isn't visible Set this behavior to an object...
static readonly DependencyProperty CollapseableColumnProperty
Attached DependencyProperty to indicate whether the GridViewColumnHeader is collapseable.
static bool GetCollapseableColumn(DependencyObject obj)
Get the value of the CollapseableColumn attached property from a DependencyObject.
static void SetCollapseableColumn(DependencyObject obj, bool value)
Sets the value of the CollapseableColumn attached property on a DependencyObject.