using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; using Prism.Events; using Prism.Ioc; using Prism.Services.Dialogs; using SWS.CAD.Event; using SWS.Commons; using SWS.Model; //using Teigha.DatabaseServices; using Teigha.GraphicsInterface; using Teigha.GraphicsSystem; using Telerik.Windows.Controls; using Unity; using static System.Net.Mime.MediaTypeNames; using Label = System.Windows.Controls.Label; using WControls = System.Windows.Controls; namespace SWS.CAD.Views.CustomControl { public class GridSouce { /// /// 属性Grid /// public PropertyGrid ProGrid { get; set; } /// /// 属性值 /// public SWS.Model.propertyModel Source { get; set; } /// /// 控件名称 /// public string ControlName { get; set; } /// /// 是否最后一个属性 /// public bool isLast { get; set; } } /// /// 自定义属性显示控件 /// public class PropertyGrid : StackPanel, INotifyPropertyChanged { static IEventAggregator eventAggregator; static PropertyGrid() { //设置该控件引用样式的键 // set the key to reference the style for this control FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata( typeof(PropertyGrid), new FrameworkPropertyMetadata(typeof(PropertyGrid))); eventAggregator = GlobalObject.container.Resolve(); } #region 字段 /// /// 记录一个板块对应的Grid /// private Dictionary _KeyValuePairs = new Dictionary(); /// /// 需要显示属性的类型 /// private object _ShowProp; private static string oldTagNumber = string.Empty; #endregion #region 依赖属性 /// /// 显示该类的属性编辑 /// public object ShowProp { get { return (object)GetValue(ShowPropProperty); } set { SetValue(ShowPropProperty, value); OnPropertyChanged("ShowProp"); } } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } // Using a DependencyProperty as the backing store for ShowProp. This enables animation, styling, binding, etc... public static readonly DependencyProperty ShowPropProperty = DependencyProperty.Register("ShowProp", typeof(object), typeof(PropertyGrid), new PropertyMetadata(default(object), new PropertyChangedCallback((d, e) => { //属性更改事件 OnShowPropChanged(d, e); }))); /// /// 默认属性名称 /// public string CurrentPropertyName { get { return GetValue(ShowPropertyName).ToString(); } set { SetValue(ShowPropertyName, value); OnPropertyChanged("CurrentPropertyName"); } } public static readonly DependencyProperty ShowPropertyName = DependencyProperty.Register("CurrentPropertyName", typeof(object), typeof(PropertyGrid), new PropertyMetadata(default(object), new PropertyChangedCallback((d, e) => { }))); /// /// 默认属性名称 /// public bool IsBasicGroup { get { return bool.Parse(GetValue(BasicGroup).ToString()); } set { SetValue(BasicGroup, value); OnPropertyChanged("IsBasicGroup"); } } public static readonly DependencyProperty BasicGroup = DependencyProperty.Register("IsBasicGroup", typeof(object), typeof(PropertyGrid), new PropertyMetadata(default(object), new PropertyChangedCallback((d, e) => { var sender = d as PropertyGrid; ObservableCollection listPairs = (ObservableCollection)sender.ShowProp; if (listPairs != null && listPairs.Any()) { sender.Children.Clear(); sender._KeyValuePairs.Clear(); for (int i = 0; i < listPairs.Count; i++) { var isLast = i == listPairs.Count - 1;//最后一个属性 if (!isLast) { var item1 = listPairs[i]; var item2 = listPairs[i + 1]; isLast = item1.GroupName != item2.GroupName;//当前属性与下个属性的分组不一样,则当前属性是在分组的最后一个属性 } CreatePropertyControl(sender, listPairs[i], i, isLast); } } }))); #endregion #region private方法 /// /// ShowProp属性更改事件 /// /// /// private static void OnShowPropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var sender = d as PropertyGrid; sender.Children.Clear(); sender._KeyValuePairs.Clear(); var newValue = e.NewValue; if (newValue != null) { //Type t = newValue.GetType(); //sender._ShowProp = newValue; //Object[] obj = t.GetProperties(); ////取属性上的自定义特性 //foreach (PropertyInfo propInfo in obj) //{ // CreateControlByAttribute(sender, newValue, propInfo); //} //Object[] objFields = t.GetFields(); ////取公有字段上的自定义特性 //foreach (FieldInfo propInfo in objFields) //{ // CreateControlByAttribute(sender, newValue, propInfo); //} //Object[] objMethods = t.GetMethods(); ////取公有方法上的自定义特性 //foreach (MethodInfo propInfo in objMethods) //{ // CreateControlByAttribute(sender, newValue, propInfo); //} ////CJB //ObservableCollection listProperty = (ObservableCollection)newValue; //foreach (propertyModel model in listProperty) //{ // CreatePropertyControl(sender, model); //} var listPro = (ObservableCollection)newValue; //foreach (propertyModel model in listPro) //{ // var isLast = listPro.Last() == model; // CreatePropertyControl(sender, model, isLast); //} for (int i = 0; i < listPro.Count; i++) { var isLast = false; if (!sender.IsBasicGroup) { isLast = i == listPro.Count - 1;//最后一个属性 if (!isLast) { var item1 = listPro[i]; var item2 = listPro[i + 1]; isLast = item1.GroupName != item2.GroupName;//当前属性与下个属性的分组不一样,则当前属性是在分组的最后一个属性 } } else { var item = listPro[i]; var list = listPro.Where(a => a.IsBasicGroup = item.IsBasicGroup).ToList(); if (list != null && list.Count() != 0) { isLast = item.DisplayText == list.Last().DisplayText; } } CreatePropertyControl(sender, listPro[i], i, isLast); } } } /// /// 根据属性特征创建控件 /// /// /// /// 是否最后一个 private static void CreatePropertyControl(PropertyGrid sender, Model.propertyModel model, int index, bool isLast) { //获取编辑的属性特征 LsPropertyGridAttribute attr = new LsPropertyGridAttribute(model.ControlTypeName, model.GroupName, model.DisplayText, model.Item); Create(sender, attr, model, index, isLast); } /// /// 根据属性特征创建控件 /// /// /// /// /// private static void CreateControlByAttribute(PropertyGrid sender, object Source, MemberInfo memberInfo) { //object[] objAttrs = memberInfo.GetCustomAttributes(typeof(LsPropertyGridAttribute), true); //if (objAttrs.Length > 0) //{ // //获取编辑的属性特征 // LsPropertyGridAttribute attr = objAttrs[0] as LsPropertyGridAttribute; // if (attr != null) // { // //Console.WriteLine("Type : {0}", attr.TypeName); // Create(sender, attr, Source, memberInfo); // } //} } /// /// 创建 /// /// PropertyGrid /// /// 绑定的对象 /// 是否最后一个属性 public static void Create(PropertyGrid sender, LsPropertyGridAttribute attr, object Source, int index, bool isLast, MemberInfo memberInfo = null) { double positionLeft = 5;//距离左边 double positionTop = 10;//距离上 Model.propertyModel pro = (Model.propertyModel)Source; if (sender.IsBasicGroup) { attr.Plate = pro.IsBasicGroup ? "常用属性" : "不常用属性"; } else { attr.Plate = pro.GroupName; } //判断板块是否已存在 _KeyValuePairs[attr.Plate] = grid; if (sender._KeyValuePairs.ContainsKey(attr.Plate)) { var grid = sender._KeyValuePairs[attr.Plate]; //存在直接在Grid后面添加控件 if (memberInfo == null) { CreateControl(sender, grid, attr, Source, index, isLast); } else { CreateControl(sender, grid, attr, Source, memberInfo); } } else { //板块不存在创建 TextBlock tb = new TextBlock(); tb.Text = "- " + attr.Plate; tb.HorizontalAlignment = HorizontalAlignment.Left; tb.Margin = new Thickness(positionLeft, positionTop, 0, 5); tb.FontSize = 12; //超过400才有粗效果 tb.FontWeight = FontWeight.FromOpenTypeWeight(400); tb.Visibility = Visibility.Visible; tb.MouseDown += txtGrid_MouseDown; sender.Children.Add(tb); //板块的Grid Grid grid = new Grid(); //grid.Width = 200; grid.Margin = new Thickness(positionLeft, 0, 0, 4); grid.HorizontalAlignment = HorizontalAlignment.Left; grid.Background = Brushes.Transparent; //添加左边列 var column = new ColumnDefinition(); column.Width = new GridLength(120);// GridLength.Auto; column.MaxWidth = 300; column.MinWidth = 100; grid.ColumnDefinitions.Add(column); //添加分隔列 grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(2) }); //添加右边列 var column3 = new ColumnDefinition(); column3.Width = new GridLength(1.0, GridUnitType.Auto); column3.MinWidth = 130; column3.MaxWidth = 500; grid.ColumnDefinitions.Add(column3); //添加属性组 sender._KeyValuePairs[attr.Plate] = grid; //sender._KeyValuePairs.Add(attr.Plate, grid); tb.Tag = grid; sender.Children.Add(grid); if (memberInfo == null) { CreateControl(sender, grid, attr, Source, index, isLast); } else { CreateControl(sender, grid, attr, Source, memberInfo); } } } private static void txtGrid_MouseDown(object sender, MouseButtonEventArgs e) { TextBlock tb = sender as TextBlock; Grid grid = tb.Tag as Grid; if (grid.Visibility == Visibility.Visible) { tb.Text = tb.Text.Replace("-", "+"); grid.Visibility = Visibility.Collapsed; } else if (grid.Visibility == Visibility.Collapsed) { tb.Text = tb.Text.Replace("+", "-"); grid.Visibility = Visibility.Visible; } } static double height = 25; static double width = 130; static double fontSize = 12; static int rightColumm = 2; /// /// 创建并绑定控件 /// /// /// /// private static void CreateControl(PropertyGrid sender, Grid grid, LsPropertyGridAttribute attr, object obj, int index, bool isLast) { //Control control = new Control(); SWS.Model.propertyModel Source = (SWS.Model.propertyModel)obj; string controlName = attr.Plate + index.ToString();// GlobalObject.ControlNameFilterSqcStr(Source.DisplayText); if (attr.TypeName != SWS.Model.PROPERTYType.Size) { var row = new RowDefinition(); row.MinHeight = 10; grid.RowDefinitions.Add(row); //添加行 //左边显示名称 Label lb = new Label(); lb.Name = "lbl" + controlName; if (!string.IsNullOrEmpty(Source.Unit)) { lb.Content = Source.DisplayText + $"({Source.Unit})"; lb.ToolTip = Source.DisplayText + $"({Source.Unit})"; } else { lb.Content = Source.DisplayText; lb.ToolTip = Source.DisplayText; } lb.Tag = controlName; lb.HorizontalAlignment = HorizontalAlignment.Left; lb.VerticalAlignment = VerticalAlignment.Center; lb.Margin = new Thickness(0, 0, 0, 0); lb.Height = 25; lb.FontSize = 12; lb.HorizontalAlignment = HorizontalAlignment.Stretch; lb.Foreground = new SolidColorBrush(Colors.White); lb.BorderBrush = new SolidColorBrush(Colors.Black); if (isLast) { lb.BorderThickness = new Thickness(1, 1, 0, 1); } else { lb.BorderThickness = new Thickness(1, 1, 0, 0); } //通过代码修改控件的Grid.Row属性 Grid.SetRow(lb, grid.RowDefinitions.Count - 1); Grid.SetColumn(lb, 0); grid.Children.Add(lb); //添加分隔列 var sp = new GridSplitter(); sp.Width = 2; sp.HorizontalAlignment = HorizontalAlignment.Stretch; sp.VerticalAlignment = VerticalAlignment.Stretch; sp.Background = Brushes.Gray; sp.ResizeBehavior = GridResizeBehavior.PreviousAndCurrent; sp.ShowsPreview = true; sp.ResizeDirection = GridResizeDirection.Columns; grid.Children.Add(sp); Grid.SetRow(sp, grid.RowDefinitions.Count - 1); Grid.SetColumn(sp, 1); } //根据执行属性的名称绑定到控件 Binding binding = new Binding("PropertyValue"); binding.Source = Source; binding.Mode = BindingMode.TwoWay; switch (attr.TypeName) { case SWS.Model.PROPERTYType.Folder: #region Folder double tbFolderWidth = 100; var btnFolder = new WControls.Button(); btnFolder.Name = "btn" + controlName; btnFolder.Content = "..."; btnFolder.Width = 29; btnFolder.Height = 25; btnFolder.Margin = new Thickness(1); btnFolder.BorderBrush = Brushes.Black; btnFolder.Background = Brushes.Transparent; btnFolder.HorizontalAlignment = HorizontalAlignment.Left; btnFolder.Margin = new Thickness(tbFolderWidth + 1, 0, 0, 0); btnFolder.Tag = new GridSouce() { ProGrid = sender, Source = Source, ControlName = controlName, isLast = isLast }; btnFolder.Click += new RoutedEventHandler(btnFolder_Click); //通过代码修改控件的Grid.Row属性 Grid.SetRow(btnFolder, grid.RowDefinitions.Count - 1); Grid.SetColumn(btnFolder, rightColumm); btnFolder.Style = null; btnFolder.IsEnabled = Source.IsEnable; var tbFolder = new NumericBox(); tbFolder.Name = "txt" + controlName; tbFolder.IsReadOnly = !Source.IsEnable; tbFolder.Margin = new Thickness(0); tbFolder.Width = tbFolderWidth; tbFolder.Padding = new Thickness(2, 0, 0, 0); tbFolder.Foreground = new SolidColorBrush(Colors.White); tbFolder.BorderBrush = new SolidColorBrush(Colors.Black); if (isLast) { tbFolder.BorderThickness = new Thickness(0, 1, 0, 1); } else { tbFolder.BorderThickness = new Thickness(0, 1, 0, 0); } tbFolder.Background = Brushes.Transparent; tbFolder.HorizontalAlignment = HorizontalAlignment.Left; tbFolder.VerticalContentAlignment = VerticalAlignment.Center; tbFolder.HorizontalContentAlignment = HorizontalAlignment.Left; tbFolder.Maximum = 10000; tbFolder.Minimum = -10000; tbFolder.UpDownButtonsWidth = 0; tbFolder.LostFocus += Number_LostFocus; tbFolder.GotFocus += Control_GotFocus;// Number_GotFocus; tbFolder.Tag = new GridSouce() { ProGrid = sender, Source = Source, ControlName = controlName, isLast = isLast }; Grid.SetRow(tbFolder, grid.RowDefinitions.Count - 1); Grid.SetColumn(tbFolder, rightColumm); binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit; //tbFolder.SetBinding(System.Windows.Controls.TextBox.TextProperty, binding); tbFolder.SetBinding(NumericBox.ValueProperty, binding); grid.Children.Add(btnFolder); grid.Children.Add(tbFolder); #endregion return; case SWS.Model.PROPERTYType.BoldItalic: return; case SWS.Model.PROPERTYType.Button: break; case SWS.Model.PROPERTYType.TextBox: var textBox = new WControls.TextBox(); textBox.Name = "txt" + controlName; textBox.Margin = new Thickness(0); textBox.Height = height; textBox.Width = width; textBox.FontSize = fontSize; textBox.Padding = new Thickness(2, 0, 0, 0); textBox.Foreground = new SolidColorBrush(Colors.White); textBox.BorderBrush = new SolidColorBrush(Colors.Black); if (isLast) { textBox.BorderThickness = new Thickness(0, 1, 1, 1); } else { textBox.BorderThickness = new Thickness(0, 1, 1, 0); } textBox.Background = Brushes.Transparent; textBox.HorizontalAlignment = HorizontalAlignment.Left; textBox.VerticalContentAlignment = VerticalAlignment.Center; textBox.HorizontalContentAlignment = HorizontalAlignment.Left; textBox.ToolTip = Source.PropertyValue; textBox.IsReadOnly = !Source.IsEnable; textBox.VerticalAlignment = VerticalAlignment.Center; textBox.Tag = new GridSouce() { ProGrid = sender, Source = Source, ControlName = controlName, isLast = isLast }; //失去焦点绑定 textBox.LostFocus += Text_LostFocus; textBox.GotFocus += Control_GotFocus;// Text_GotFocus; binding.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus; textBox.SetBinding(WControls.TextBox.TextProperty, binding); //通过代码修改控件的Grid.Row属性 Grid.SetRow(textBox, grid.RowDefinitions.Count - 1); Grid.SetColumn(textBox, rightColumm); grid.Children.Add(textBox); break; case SWS.Model.PROPERTYType.Number: var txtNumber = new NumericBox(); txtNumber.Name = "txt" + controlName; txtNumber.Margin = new Thickness(0); txtNumber.Height = height; txtNumber.Width = width; txtNumber.FontSize = fontSize; txtNumber.Padding = new Thickness(2, 0, 0, 0); txtNumber.Foreground = new SolidColorBrush(Colors.White); txtNumber.BorderBrush = new SolidColorBrush(Colors.Black); //txtNumber.BorderThickness = new Thickness(1, 1, 1, 1); if (isLast) { txtNumber.BorderThickness = new Thickness(0, 1, 1, 1); } else { txtNumber.BorderThickness = new Thickness(0, 1, 1, 0); } txtNumber.Background = Brushes.Transparent; txtNumber.HorizontalAlignment = HorizontalAlignment.Left; txtNumber.VerticalAlignment = VerticalAlignment.Center; txtNumber.VerticalContentAlignment = VerticalAlignment.Center; txtNumber.HorizontalContentAlignment = HorizontalAlignment.Left; txtNumber.IsReadOnly = !Source.IsEnable; binding.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus; txtNumber.Tag = new GridSouce() { ProGrid = sender, Source = Source, ControlName = controlName, isLast = isLast }; txtNumber.SetBinding(NumericBox.ValueProperty, binding); txtNumber.Maximum = 10000; txtNumber.Minimum = -10000; txtNumber.UpDownButtonsWidth = 0; txtNumber.LostFocus += Number_LostFocus; txtNumber.GotFocus += Control_GotFocus;// Number_GotFocus; txtNumber.Visibility = Visibility.Visible; //通过代码修改控件的Grid.Row属性 Grid.SetRow(txtNumber, grid.RowDefinitions.Count - 1); Grid.SetColumn(txtNumber, rightColumm); grid.Children.Add(txtNumber); break; case SWS.Model.PROPERTYType.CheckBox: var checkBox = new CheckBox(); checkBox.Style = null; checkBox.Name = "checkBox" + controlName; checkBox.Margin = new Thickness(0); checkBox.Height = height; checkBox.Width = width; checkBox.IsEnabled = Source.IsEnable; checkBox.VerticalAlignment = VerticalAlignment.Center; checkBox.VerticalContentAlignment = VerticalAlignment.Center; checkBox.HorizontalAlignment = HorizontalAlignment.Center; checkBox.BorderBrush = new SolidColorBrush(Colors.Black); if (isLast) { checkBox.BorderThickness = new Thickness(0, 1, 1, 1); } else { checkBox.BorderThickness = new Thickness(0, 1, 1, 0); } checkBox.Tag = new GridSouce() { ProGrid = sender, Source = Source, ControlName = controlName, isLast = isLast }; checkBox.SetBinding(CheckBox.IsCheckedProperty, binding); //通过代码修改控件的Grid.Row属性 var bor = new Border(); bor.BorderBrush = new SolidColorBrush(Colors.Black); if (isLast) { bor.BorderThickness = new Thickness(0, 1, 1, 1); } else { bor.BorderThickness = new Thickness(0, 1, 1, 0); } Grid.SetRow(bor, grid.RowDefinitions.Count - 1); Grid.SetColumn(bor, rightColumm); grid.Children.Add(bor); Grid.SetRow(checkBox, grid.RowDefinitions.Count - 1); Grid.SetColumn(checkBox, rightColumm); grid.Children.Add(checkBox); break; case SWS.Model.PROPERTYType.Label: break; case SWS.Model.PROPERTYType.ComboBox: var cbox = new RadComboBox(); cbox.Margin = new Thickness(0); cbox.Height = height - 1; cbox.Width = width; cbox.FontSize = fontSize; cbox.Padding = new Thickness(0); cbox.Foreground = new SolidColorBrush(Colors.Blue); cbox.BorderBrush = new SolidColorBrush(Colors.Black); cbox.Background = Brushes.Transparent; cbox.HorizontalAlignment = HorizontalAlignment.Left; cbox.VerticalContentAlignment = VerticalAlignment.Center; cbox.HorizontalContentAlignment = HorizontalAlignment.Left; cbox.VerticalAlignment = VerticalAlignment.Center; //cbox.Style = GlobalObject.TransparentComboBoxStyle; cbox.BorderThickness = new Thickness(0, 1, 1, 1); //这个必须放在前面设置 if (attr.Tag != null && !attr.Tag.Equals("")) { cbox.DisplayMemberPath = "Value"; cbox.Items.Add(new KeyValueModel() { Key = "", Value = "" }); Dictionary items = (Dictionary)Source.Item; foreach (var item in items) { if (string.IsNullOrEmpty(item.Key) || string.IsNullOrEmpty(item.Value)) { continue; } KeyValueModel model = new KeyValueModel(); model.Key = item.Key; model.Value = item.Value; cbox.Items.Add(model); } } cbox.TextBoxStyle = GlobalObje.WhiteStyle; cbox.Foreground = new SolidColorBrush(Colors.Blue); cbox.Background = new SolidColorBrush(Color.FromRgb(45, 49, 53)); cbox.IsEditable = true; cbox.IsEnabled = Source.IsEnable; cbox.Tag = new GridSouce() { ProGrid = sender, Source = Source, ControlName = controlName, isLast = isLast }; cbox.SetBinding(RadComboBox.TextProperty, binding); //cbox.SetBinding(WControls.ComboBox.TextProperty, binding); cbox.SelectionChanged += cbox_SelectionChanged; cbox.LostFocus += cbox_LostFocus; cbox.GotFocus += Control_GotFocus; //通过代码修改控件的Grid.Row属性 Grid.SetRow(cbox, grid.RowDefinitions.Count - 1); Grid.SetColumn(cbox, rightColumm); grid.Children.Add(cbox); break; case SWS.Model.PROPERTYType.MultiSelectComboBox: var mscbox = new MultiSelectComboBox(); mscbox.IsEnabled = Source.IsEnable; mscbox.Margin = new Thickness(0); mscbox.Height = height - 1; mscbox.Width = width; mscbox.FontSize = fontSize; mscbox.Foreground = new SolidColorBrush(Colors.Black); mscbox.BorderBrush = new SolidColorBrush(Colors.Black); mscbox.BorderThickness = new Thickness(0, 1, 1, 1); mscbox.Background = Brushes.Black; mscbox.HorizontalAlignment = HorizontalAlignment.Left; mscbox.VerticalContentAlignment = VerticalAlignment.Center; mscbox.HorizontalContentAlignment = HorizontalAlignment.Left; mscbox.VerticalAlignment = VerticalAlignment.Center; mscbox.SelectionMode = WControls.SelectionMode.Multiple; //这个必须放在前面设置 if (!attr.Tag.Equals("")) { mscbox.DisplayMemberPath = "Value"; Dictionary items = (Dictionary)Source.Item; foreach (var item in items) { if (string.IsNullOrEmpty(item.Key) || string.IsNullOrEmpty(item.Value)) { continue; } KeyValueModel model = new KeyValueModel(); model.Key = item.Key; model.Value = item.Value; mscbox.Items.Add(model); if (Source.PropertyValue.Contains(model.Value)) { mscbox.SelectedItems.Add(model); } } } mscbox.Tag = new GridSouce() { ProGrid = sender, Source = Source, ControlName = controlName, isLast = isLast }; mscbox.SetBinding(MultiSelectComboBox.TextProperty, binding); //mscbox.SelectionChanged += multcbox_SelectionChanged; mscbox.GotFocus += Control_GotFocus; mscbox.LostFocus += Control_LostFocus; //mscbox.Text = Source.PropertyValue; //通过代码修改控件的Grid.Row属性 Grid.SetRow(mscbox, grid.RowDefinitions.Count - 1); Grid.SetColumn(mscbox, rightColumm); grid.Children.Add(mscbox); break; } //control.VerticalAlignment = VerticalAlignment.Center; ////通过代码修改控件的Grid.Row属性 //Grid.SetRow(control, grid.RowDefinitions.Count - 1); //Grid.SetColumn(control, 1); //grid.Children.Add(control); } private static void btnFolder_Click(object sender, RoutedEventArgs e) { var btnFolde = sender as Button; var gridsource = btnFolde.Tag as GridSouce; var grid = gridsource.ProGrid; var source = gridsource.Source; IDialogParameters x = new Prism.Services.Dialogs.DialogParameters(); x.Add(GlobalObject.dialogPar.unitTypeId.ToString(), source.UnitTypeId); x.Add(GlobalObject.dialogPar.textYes.ToString(), source.Unit); var _dialogService = GlobalObject._prismContainer.Resolve(); _dialogService.ShowDialog(nameof(DialogUnitSelect), x, (RES) => { if (RES.Result == ButtonResult.Yes) { var unit = RES.Parameters.GetValue(GlobalObject.dialogPar.unit.ToString()); var controlame = "lbl" + gridsource.ControlName; Label label = null; source.Unit = unit.UnitName; label = GlobalObje.GetChildObject