|
1 | | -using System.Windows; |
| 1 | +using CookPopularCSharpToolkit.Communal; |
| 2 | +using CookPopularCSharpToolkit.Windows; |
| 3 | +using System; |
| 4 | +using System.Linq; |
| 5 | +using System.Windows; |
2 | 6 | using System.Windows.Controls; |
| 7 | +using System.Xml.Linq; |
3 | 8 |
|
4 | 9 |
|
5 | 10 |
|
|
12 | 17 | namespace CookPopularControl.Controls |
13 | 18 | { |
14 | 19 | /// <summary> |
15 | | - /// <see cref="ListView"/>的附加属性基类 |
| 20 | + /// 表示<see cref="GridViewColumn"/>的附加属性基类 |
| 21 | + /// </summary> |
| 22 | + public class GridViewColumnAssistant |
| 23 | + { |
| 24 | + public static GridLength GetColumnMinWidth(DependencyObject obj) => (GridLength)obj.GetValue(ColumnMinWidthProperty); |
| 25 | + public static void SetColumnMinWidth(DependencyObject obj, GridLength value) => obj.SetValue(ColumnMinWidthProperty, value); |
| 26 | + /// <summary> |
| 27 | + /// 标识<see cref="GridViewColumnHeader"/>列项最小宽度 |
| 28 | + /// </summary> |
| 29 | + public static readonly DependencyProperty ColumnMinWidthProperty = |
| 30 | + DependencyProperty.RegisterAttached("ColumnMinWidth", typeof(GridLength), typeof(GridViewColumnAssistant), new PropertyMetadata(GridLength.Auto, OnColumnMinWidthChanged)); |
| 31 | + |
| 32 | + private static void OnColumnMinWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 33 | + { |
| 34 | + if (d is GridViewColumn column) |
| 35 | + { |
| 36 | + var defaultGridViewColumnHeaderStyle = ResourceHelper.GetResource<Style>(typeof(GridViewColumnHeader)); |
| 37 | + Style style = new Style(typeof(GridViewColumnHeader), defaultGridViewColumnHeaderStyle); |
| 38 | + var setter = new Setter(GridViewColumnHeader.MinWidthProperty, GetColumnMinWidth(column).Value); |
| 39 | + style.Setters.Add(setter); |
| 40 | + column.HeaderContainerStyle = style; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + public static Thickness GetColumnHeaderPadding(DependencyObject obj) => (Thickness)obj.GetValue(ColumnHeaderPaddingProperty); |
| 46 | + internal static void SetColumnHeaderPadding(DependencyObject obj, Thickness value) => obj.SetValue(ColumnHeaderPaddingProperty, value); |
| 47 | + /// <summary> |
| 48 | + /// 标识<see cref="GridViewColumnHeader"/>的内边距 |
| 49 | + /// 暂时无效 |
| 50 | + /// </summary> |
| 51 | + public static readonly DependencyProperty ColumnHeaderPaddingProperty = |
| 52 | + DependencyProperty.RegisterAttached("ColumnHeaderPadding", typeof(Thickness), typeof(GridViewColumnAssistant), new PropertyMetadata(default(Thickness), OnColumnHeaderPaddingChanged)); |
| 53 | + |
| 54 | + private static void OnColumnHeaderPaddingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 55 | + { |
| 56 | + if (d is GridViewColumn column) |
| 57 | + { |
| 58 | + var defaultGridViewColumnHeaderStyle = ResourceHelper.GetResource<Style>(typeof(GridViewColumnHeader)); |
| 59 | + Style style = new Style(typeof(GridViewColumnHeader), defaultGridViewColumnHeaderStyle); |
| 60 | + var setter = new Setter(ColumnHeaderPaddingProperty, GetColumnHeaderPadding(column)); |
| 61 | + //var setter = new Setter(GridViewColumnHeader.PaddingProperty, GetColumnHeaderPadding(column)); |
| 62 | + |
| 63 | + //var setter = (Setter)style.Setters.FirstOrDefault(setter => ((Setter)setter).Property == GridViewColumnHeader.PaddingProperty)!; |
| 64 | + //setter.Value = GetColumnHeaderPadding(column); |
| 65 | + |
| 66 | + style.Setters.Add(setter); |
| 67 | + column.HeaderContainerStyle = style; |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + /// <summary> |
| 74 | + /// 表示<see cref="ListView"/>的附加属性基类 |
16 | 75 | /// </summary> |
17 | 76 | public class ListViewAssistant |
18 | 77 | { |
| 78 | + public static double GetColumnHeaderHeight(DependencyObject obj) => (double)obj.GetValue(ColumnHeaderHeightProperty); |
| 79 | + public static void SetColumnHeaderHeight(DependencyObject obj, double value) => obj.SetValue(ColumnHeaderHeightProperty, value); |
| 80 | + /// <summary> |
| 81 | + /// 标识<see cref="GridViewColumnHeader"/>的标头高度 |
| 82 | + /// </summary> |
| 83 | + public static readonly DependencyProperty ColumnHeaderHeightProperty = |
| 84 | + DependencyProperty.RegisterAttached("ColumnHeaderHeight", typeof(double), typeof(ListViewAssistant), new PropertyMetadata(ValueBoxes.Double30Box)); |
| 85 | + |
| 86 | + |
| 87 | + public static bool GetIsColumnHeaderFontWeight(DependencyObject obj) => (bool)obj.GetValue(IsColumnHeaderFontWeightProperty); |
| 88 | + public static void SetIsColumnHeaderFontWeight(DependencyObject obj, bool value) => obj.SetValue(IsColumnHeaderFontWeightProperty, ValueBoxes.BooleanBox(value)); |
| 89 | + /// <summary> |
| 90 | + /// 表示<see cref="GridViewColumnHeader"/>是否采用粗体 |
| 91 | + /// </summary> |
| 92 | + public static readonly DependencyProperty IsColumnHeaderFontWeightProperty = |
| 93 | + DependencyProperty.RegisterAttached("IsColumnHeaderFontWeight", typeof(bool), typeof(ListViewAssistant), new PropertyMetadata(ValueBoxes.FalseBox)); |
| 94 | + |
| 95 | + |
19 | 96 | public static Thickness GetListViewItemPadding(DependencyObject obj) => (Thickness)obj.GetValue(ListViewItemPaddingProperty); |
20 | 97 | public static void SetListViewItemPadding(DependencyObject obj, Thickness value) => obj.SetValue(ListViewItemPaddingProperty, value); |
| 98 | + /// <summary> |
| 99 | + /// 表示<see cref="ListViewItem"/>的内边距 |
| 100 | + /// </summary> |
21 | 101 | public static readonly DependencyProperty ListViewItemPaddingProperty = |
22 | 102 | DependencyProperty.RegisterAttached("ListViewItemPadding", typeof(Thickness), typeof(ListViewAssistant), new PropertyMetadata(default(Thickness))); |
23 | 103 | } |
|
0 commit comments