// 创建一个动态属性编辑项 private Grid createPropEntryGrid(PropertyInfo propInfo) { Grid grid = new Grid(); Label lbSCParamName = new Label(); lbSCParamName.Content = propInfo.Name; grid.Children.Add(lbSCParamName); ELogicType logicType = AssemblyUtil.GetPropertyLogicType(propInfo); if (logicType == ELogicType.Int || logicType == ELogicType.Percent) { TextBox tbSCParamValue = new TextBox(); Binding tbBinding = new Binding(propInfo.Name); tbBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; tbSCParamValue.SetBinding(TextBox.TextProperty, tbBinding); tbSCParamValue.Margin = new Thickness(80, 4, 0, 4); grid.Children.Add(tbSCParamValue); } else if (logicType == ELogicType.String) { LogManager.Instance.Error("此版本不支持String类型的动态类属性: " + propInfo.Name); } else if (logicType == ELogicType.BuffType) { Button btnBuff = new Button(); Binding txtBinding = new Binding(propInfo.Name); txtBinding.Converter = (IValueConverter)Application.Current.TryFindResource("ID2BuffNameConverter"); btnBuff.SetBinding(Button.ContentProperty, txtBinding); btnBuff.Margin = new Thickness(80, 4, 0, 4); grid.Children.Add(btnBuff); btnBuff.Click += (o, re) => { BuffPickWindow buffPickWindow = new BuffPickWindow(); if (buffPickWindow.ShowDialog() == true) { propInfo.SetValue(btnBuff.DataContext, buffPickWindow.PickedBuffType); } }; } else if (logicType == ELogicType.Element) { ComboBox cb = new ComboBox(); cb.ItemsSource = Enum.GetNames(typeof(EElement)); Binding binding = new Binding(propInfo.Name); binding.Converter = (IValueConverter)Application.Current.TryFindResource("Enum2StrConverter"); binding.ConverterParameter = typeof(EElement); cb.SetBinding(ComboBox.TextProperty, binding); cb.Margin = new Thickness(80, 4, 0, 4); grid.Children.Add(cb); } else { LogManager.Instance.Error("配置了不支持的参数类型: " + propInfo.Name + " - " + logicType); } return(grid); }
// 创建一个动态属性编辑项 private Grid createPropEntryGrid(PropertyInfo propInfo) { Grid grid = new Grid(); Label lbSCParamName = new Label(); lbSCParamName.Content = propInfo.Name; grid.Children.Add(lbSCParamName); ELogicType logicType = AssemblyUtil.GetPropertyLogicType(propInfo); if (logicType == ELogicType.Int || logicType == ELogicType.Percent) { TextBox tbSCParamValue = new TextBox(); Binding tbBinding = new Binding(propInfo.Name); tbBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; tbSCParamValue.SetBinding(TextBox.TextProperty, tbBinding); tbSCParamValue.Margin = new Thickness(80, 4, 0, 4); grid.Children.Add(tbSCParamValue); } else if (logicType == ELogicType.String) { LogManager.Instance.Error("此版本不支持String类型的动态类属性: " + propInfo.Name); } else if (logicType == ELogicType.BuffType) { Button btnBuff = new Button(); Binding txtBinding = new Binding(propInfo.Name); txtBinding.Converter = (IValueConverter)Application.Current.TryFindResource("ID2BuffNameConverter"); btnBuff.SetBinding(Button.ContentProperty, txtBinding); btnBuff.Margin = new Thickness(80, 4, 0, 4); grid.Children.Add(btnBuff); btnBuff.Click += (o, re) => { BuffPickWindow buffPickWindow = new BuffPickWindow(); if (buffPickWindow.ShowDialog() == true) { propInfo.SetValue(btnBuff.DataContext, buffPickWindow.PickedBuffType); } }; } else if (logicType == ELogicType.Element) { ComboBox cb = new ComboBox(); cb.ItemsSource = Enum.GetNames(typeof(EElement)); Binding binding = new Binding(propInfo.Name); binding.Converter = (IValueConverter)Application.Current.TryFindResource("Enum2StrConverter"); binding.ConverterParameter = typeof(EElement); cb.SetBinding(ComboBox.TextProperty, binding); cb.Margin = new Thickness(80, 4, 0, 4); grid.Children.Add(cb); } else { LogManager.Instance.Error("配置了不支持的参数类型: " + propInfo.Name + " - " + logicType); } return grid; }