using System.Windows.Controls; using System.Windows; namespace YY.Admin.Core { /// /// DataGrid绑定数据源描述 /// public class BindDescriptionAttribute : Attribute { /// /// 列名 /// public string HeaderName { get; set; } /// /// 显示为 /// public ShowScheme ShowAs { get; set; } /// /// 显示顺序 /// public int DisplayIndex { get; set; } /// /// DataGrid列绑定属性名称 /// public string PropertyName { get; set; } /// /// 应用内的容模板Key /// public string ResourceKey { get; set; } /// /// 列宽 /// public DataGridLength Width { get; set; } /// /// 列宽ByGrid /// public GridLength CloumnWidth { get; set; } /// /// DataGrid绑定数据源描述 /// /// 列名 /// 显示为 /// 宽度 /// 显示顺序 /// 自定义列Key public BindDescriptionAttribute(string headerName, ShowScheme showAs = ShowScheme.普通文本, string width = "Auto", int displayIndex = 0, string resourceKey = "") { this.HeaderName= headerName; DisplayIndex = displayIndex; ResourceKey = resourceKey; ShowAs = showAs; var convert = new DataGridLengthConverter(); Width = (DataGridLength)convert.ConvertFrom(width); var gridCOnvert = new GridLengthConverter(); CloumnWidth = (GridLength)gridCOnvert.ConvertFrom(width); if (showAs == ShowScheme.自定义 && string.IsNullOrWhiteSpace(resourceKey)) throw new ArgumentException($"自定义列时需要指定{nameof(resourceKey)}参数!"); } } /// /// 展示方式 /// public enum ShowScheme { 普通文本 = 1, 自定义 = 4 } }