Change move indication (Color and width) for ColumnHeader
If you want to change the Moving indicator use this helper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
public class ListViewHelper { #region IndicatorWidth public static double GetIndicatorWidth(DependencyObject obj) => (double)obj.GetValue(IndicatorWidthProperty); public static void SetIndicatorWidth(DependencyObject obj, double value) => obj.SetValue(IndicatorWidthProperty, value); public static readonly DependencyProperty IndicatorWidthProperty = DependencyProperty.RegisterAttached("IndicatorWidth", typeof(double), typeof(ListViewHelper), new PropertyMetadata(2.0)); #endregion #region IndicatorColor public static Brush GetIndicatorColor(DependencyObject obj) => (Brush)obj.GetValue(IndicatorColorProperty); public static void SetIndicatorColor(DependencyObject obj, Brush value) => obj.SetValue(IndicatorColorProperty, value); public static readonly DependencyProperty IndicatorColorProperty = DependencyProperty.RegisterAttached("IndicatorColor", typeof(Brush), typeof(ListViewHelper), new PropertyMetadata(null ,(ss,ee) => { if(ss is ListView lv) { lv.Loaded += delegate { if (FindChild<GridViewHeaderRowPresenter>(lv) is GridViewHeaderRowPresenter gh) { if (FindChild<Separator>(gh) is Separator sep) { sep.IsVisibleChanged += delegate { if (FindChild<Border>(sep) is Border b) { b.Background = GetIndicatorColor(lv); sep.Width = GetIndicatorWidth(lv); b.Width = GetIndicatorWidth(lv); } }; } } }; } } )); #endregion private static T FindChild<T>(DependencyObject parent, string childName = null) where T : DependencyObject { if (parent == null) return null; T foundChild = null; int childrenCount = VisualTreeHelper.GetChildrenCount(parent); for (int i = 0; i < childrenCount; i++) { var child = VisualTreeHelper.GetChild(parent, i); T childType = child as T; if (childType == null) { foundChild = FindChild<T>(child, childName); if (foundChild != null) break; } else if (!string.IsNullOrEmpty(childName)) { var frameworkElement = child as FrameworkElement; if (frameworkElement != null && frameworkElement.Name == childName) { // if the child's name is of the request name foundChild = (T)child; break; } } else { // child element found. foundChild = (T)child; break; } } return foundChild; } } |
and use like
1 2 3 4 |
<ListView x:Name="lv" local:ListViewHelper.IndicatorColor="red" local:ListViewHelper.IndicatorWidth="3" ItemsSource="{Binding GesItems}"> |
Categories: Non classé
Commentaires récents